Repository navigation
MAUI iOS app launch crashes #4205
Description
Package
Sentry.Maui
.NET Flavor
.NET
.NET Version
MAUI 9+
OS
iOS
OS Version
No response
Development Environment
Visual Studio v17.x
SDK Version
5.6.0 and latest
Self-Hosted Sentry Version
No response
Workload Versions
My MAUI iOS app is crashing in launch in Simulator 18. MAUI 9,
System.Exception: Could not create an native instance of the type 'Sentry.CocoaSdk.SentryOptions': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.
at Foundation.NSObject.InitializeObject(Boolean alloced)
at Foundation.NSObject..ctor(NSObjectFlag x)
at Sentry.CocoaSdk.SentryOptions..ctor()
at Sentry.SentrySdk.InitSentryCocoaSdk(SentryOptions options)
at Sentry.SentrySdk.InitHub(SentryOptions options)
at Sentry.SentrySdk.Init(SentryOptions options)
at Sentry.Maui.Internal.SentryMauiInitializer.Initialize(IServiceProvider services)
at Microsoft.Maui.Hosting.MauiAppBuilder.Build()
at Sentry.reproduce.MauiProgram.CreateMauiApp() in /private/tmp/Sentry.reproduce/Sentry.reproduce/MauiProgram.cs:line 33
at Sentry.reproduce.AppDelegate.CreateMauiApp() in /private/tmp/Sentry.reproduce/Sentry.reproduce/Platforms/MacCatalyst/AppDelegate.cs:line 8
at Microsoft.Maui.MauiUIApplicationDelegate.WillFinishLaunching(UIApplication application, NSDictionary launchOptions)
at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
I tried the suggested workaround, but it didn’t resolve the issue. In fact, adding the following snippet—as per the workaround—causes another library to break:
---> System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
<PropertyGroup>
<_LibXamarinLinkMode>static</_LibXamarinLinkMode>
<_LibMonoLinkMode>static</_LibMonoLinkMode>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<Target Name="_OverwriteReferencesLinkerFlags" BeforeTargets="_LinkNativeExecutable">
<!-- Remove the `-u` prefix from `_ReferencesLinkerFlags` so we can give the output file to the platform linker -->
<!-- NOTE: This step is actually also done after LinkNativeCode task, but we cannot intercept it differently -->
<WriteLinesToFile SessionId="$(BuildSessionId)" File="$(_MtouchSymbolsList)" Lines="@(_ReferencesLinkerFlags->'%(Identity)'->Substring (2))" Overwrite="true" />
<ItemGroup>
<!-- Backup collected required symbols -->
<_ReferencesLinkerFlagsBackup Include="@(_ReferencesLinkerFlags)" />
<!-- Clear `_ReferencesLinkerFlags` to prevent required symbols to be passed in -u_symbolName format -->
<_ReferencesLinkerFlags Remove="@(_ReferencesLinkerFlags)" />
<!-- Instruct platform linker to only export required symbols -->
<_ReferencesLinkerFlags Include="-exported_symbols_list" />
<_ReferencesLinkerFlags Include="$(_MtouchSymbolsList)" />
</ItemGroup>
</Target>
<Target Name="_RestoreReferencesLinkerFlags" AfterTargets="_LinkNativeExecutable">
<ItemGroup>
<_ReferencesLinkerFlags Remove="@(_ReferencesLinkerFlags)" />
<_ReferencesLinkerFlags Include="@(_ReferencesLinkerFlagsBackup)" />
</ItemGroup>
</Target>
UseSentry or SentrySdk.Init call
.UseSentry(options =>
{
// The DSN is the only required setting.
options.Dsn = "aaaaabbbbb;
#if DEBUG
options.Debug = true;
#else
options.Debug = false;
#endif
options.SendDefaultPii = true;
options.AutoSessionTracking = true;
options.IsGlobalModeEnabled = true;
options.AttachStacktrace = true;
options.AttachScreenshot = true;
options.CaptureFailedRequests = true;
})
Steps to Reproduce
Include Sentry nuget and just compile the app
app launch getting crashed
Expected Result
the app should not crash
Actual Result
app crash as below stacktrace
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
- StatusShow more project fieldsWaiting for: Product Owner
Activity
jamescrosswell commentedon May 21, 2025
@007vel I think this is related to broken bindings. This should be fixed in #4202 (which is included in the 5.8.0 release... hopefully that will be available within 12-24 hours).
If you need to correct this urgently, you'll need to revert to version
5.5.1.jamescrosswell commentedon May 21, 2025
@007vel just following up to say that we just shipped version 5.8.0 which rolls back the broken iOS SDK:
https://github.com/getsentry/sentry-dotnet/releases/tag/5.8.0
If you can confirm that bumping to 5.8.0 resolves the issue, that would be much appreciated 🙏🏻
007vel commentedon May 22, 2025
@jamescrosswell I've tried using version 5.8.0, but the issue still persists.
The same code works fine on Simulator 17, but it breaks on Simulator 18 and above.
007vel commentedon May 23, 2025
Adding a console log
jamescrosswell commentedon May 25, 2025
@007vel I don't think that workaround is a good idea. Sentry needs to be able to load the
Sentry.CocoaSdk.SentryOptionsclass.I'm not able to reproduce this however. If you're still seeing this after upgrading to version 5.8.0, would you be able to put together a minimal application that reproduces this behaviour and share it (e.g. as a GitHub repo)?
007vel commentedon May 30, 2025
There was an issue during my project startup — a delay in loading all static resources from App.xaml.
I had initialized the SDK in App.xaml.cs instead of MauiProgram.
After moving SentrySdk.Init() to the correct place, everything is working fine now.