Skip to content

MAUI iOS app launch crashes #4205

Description

@007vel

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

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on May 20, 2025
  2. jamescrosswell commented on May 21, 2025

    @jamescrosswell
    Collaborator

    @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.

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on May 21, 2025
  4. jamescrosswell commented on May 21, 2025

    @jamescrosswell
    Collaborator

    @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 🙏🏻

  5. 007vel commented on May 22, 2025

    @007vel
    Author

    @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.

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on May 22, 2025
  7. 007vel commented on May 23, 2025

    @007vel
    Author

    Adding a console log

    dyld[5625]: Symbol not found: _OBJC_CLASS_$_SentryCrashExceptionApplication
    
    	  Referenced from: <AEE2021D-52D1-3CE3-8FD5-1A217631D7C1> /private/var/containers/Bundle/Application/B8C8C799-7C72-4837-861B-64DF478C3E2B/SevenMobileMAUI.app/SevenMobileMAUI
    
    	  Expected in:     <5C4DA776-C29E-3CFC-AC25-F78E1B2C8FF4> /private/var/containers/Bundle/Application/B8C8C799-7C72-4837-861B-64DF478C3E2B/SevenMobileMAUI.app/Frameworks/Sentry.framework/Sentry
    
    	12:54:27  Acquired tunnel connection to device.
    
    	12:54:27  Enabling developer disk image services.
    
    	12:54:27  Acquired usage assertion.
    
    	Launched application with io.**.mobile bundle identifier.
    
    	Waiting for the application to terminate...
    
    	App terminated due to signal 6.
    
    xcrun devicectl -j /var/folders/cg/hn1byzl54fsf54wpptv2tfm80000gn/T/tmpIr2fIU.tmp device process launch --terminate-existing --device 00008110-000E481636C2401E --console io.**.mobile
    
    dyld[5625]: Symbol not found: _OBJC_CLASS_$_SentryCrashExceptionApplication
    
      Referenced from: <AEE2021D-52D1-3CE3-8FD5-1A217631D7C1> /private/var/containers/Bundle/Application/B8C8C799-7C72-4837-861B-64DF478C3E2B/SevenMobileMAUI.app/SevenMobileMAUI
    
      Expected in:     <5C4DA776-C29E-3CFC-AC25-F78E1B2C8FF4> /private/var/containers/Bundle/Application/B8C8C799-7C72-4837-861B-64DF478C3E2B/SevenMobileMAUI.app/Frameworks/Sentry.framework/Sentry
    
    12:54:27  Acquired tunnel connection to device.
    
    12:54:27  Enabling developer disk image services.
    
    12:54:27  Acquired usage assertion.
    
    Launched application with io.***.mobile bundle identifier.
    
    Waiting for the application to terminate...
    
    App terminated due to signal 6.
    
    error HE1045: Failed to execute 'devicectl': 'devicectl -j /var/folders/cg/hn1byzl54fsf54wpptv2tfm80000gn/T/tmpIr2fIU.tmp device process launch --terminate-existing --device 00008110-000E481636C2401E --console io.***.mobile' returned the exit code 1.
    
    error HE1046: Additional output: xcrun devicectl -j /var/folders/cg/hn1byzl54fsf54wpptv2tfm80000gn/T/tmpIr2fIU.tmp device process launch --terminate-existing --device 00008110-000E481636C2401E --console io.**.mobile
    
    error HE1046: Additional output: dyld[5625]: Symbol not found: _OBJC_CLASS_$_SentryCrashExceptionApplication
    
    error HE1046: Additional output:   Referenced from: <AEE2021D-52D1-3CE3-8FD5-1A217631D7C1> /private/var/containers/Bundle/Application/B8C8C799-7C72-4837-861B-64DF478C3E2B/SevenMobileMAUI.app/SevenMobileMAUI
    
    error HE1046: Additional output:   Expected in:     <5C4DA776-C29E-3CFC-AC25-F78E1B2C8FF4> /private/var/containers/Bundle/Application/B8C8C799-7C72-4837-861B-64DF478C3E2B/SevenMobileMAUI.app/Frameworks/Sentry.framework/Sentry
    
    error HE1046: Additional output: 12:54:27  Acquired tunnel connection to device.
    
    error HE1046: Additional output: 12:54:27  Enabling developer disk image services.
    
    error HE1046: Additional output: 12:54:27  Acquired usage assertion.
    
    error HE1046: Additional output: Launched application with io.**.mobile bundle identifier.
    
    error HE1046: Additional output: Waiting for the application to terminate...
    
    error HE1046: Additional output: App terminated due to signal 6.
    
    
  8. jamescrosswell commented on May 25, 2025

    @jamescrosswell
    Collaborator

    @007vel I don't think that workaround is a good idea. Sentry needs to be able to load the Sentry.CocoaSdk.SentryOptions class.

    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)?

  9. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on May 25, 2025
  10. 007vel commented on May 30, 2025

    @007vel
    Author

    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.

  11. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions