MAUI. In AppShell ctor Current.Services is null.
See original GitHub issuePackage
Sentry.Maui
.NET Version
6.0.0
SDK Version
3.22.0-preview.3
Steps to Reproduce
- Create empty MAUI project.
- Create and register empty ViewModel.
- Create ServiceHelper:
public static class ServiceHelper
{
public static TService GetService<TService>() => Current.GetService<TService>();
public static IServiceProvider Current =>
#if WINDOWS10_0_17763_0_OR_GREATER
MauiWinUIApplication.Current.Services;
#elif ANDROID
MauiApplication.Current.Services;
#elif IOS || MACCATALYST
MauiUIApplicationDelegate.Current.Services;
#else
null;
#endif
}
- In AppShell ctor add this:
var vm = ServiceHelper.GetService<ViewModel>();
BindingContext = vm;
- Add NuGet:
dotnet add package Sentry.Maui --prerelease
Install-Package Sentry.Maui -AllowPrereleaseVersions
- Start your app on Windows or Android (local/emulator).
Expected Result
Actual Result
OS: Android, Windows
Can be used as a workaround
No exception is thrown in this method. However, it can be called many times, you need to do a check.
Repo
You can ckeck on this repo: https://github.com/Nick4nik/Sentry-AppShell-Issue
Issue Analytics
- State:
- Created a year ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Dependency Injection is Returning Null
I tried adjusting a few of my methods and it still returns null. Any help is much appreciated. I am using .net MAUI....
Read more >NullReferenceException When Using Maui Class Library ...
Hi there, I am attempting to dynamically resolve and load my Maui pages and viewmodels and also use Devexpress controls like the DXPopup....
Read more >Transfer data from android activity to maui MainPage
I have tried [QueryProperty] with Shell.Current.GoToAsync and creating a different activity class, but that all doesn't work. So, how can I ...
Read more >7.2 and 7.1 Maui Android crashes in Release mode, but works ...
Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(ABP_7_2.Maui.ViewModels.ShellViewModel)' ...
Read more >KeepScreenOn throws error on Android - Microsoft Q&A
NullReferenceException: The current Activity can not be detected. Ensure that you have called Init in your Activity or Application class. at ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks, I will investigate. Though off hand, I don’t see how Sentry would be interfering with that. We don’t unregister anything in DI.
See #2006 for details of the fix.
Also, FYI - you can simplify your
ServiceHelper
by usingIPlatformApplication.Current?.Services
instead of separating by platform manually.