[iOS] MAUI app crashing when calling function from external library in Release mode, but works in Debug mode

Muhammad Sharif Uddin 0 Reputation points
2025-01-15T15:15:36.6666667+00:00

MAUI .NET 9, 9.0.21, targeting iOS and Android

I'm observing the app crashing on iOS when running in Release mode build from TestFlight on physical device, but works when running in Debug mode in simulators. The app crashes when a particular method is executed from an included class library Some.External.Library.dll in the app.

The same could be observed on Android where it works in Debug, but does not work in Release mode. I've found Setting the <Optimize>False</Optimize> has allowed it to work in Release mode for Android, however this still does not work in iOS in Release mode.

I have tried setting <UseInterpreter>true</UseInterpreter> but see no change.

I've also tried setting <MtouchInterpreter>-all,Some.External.Library.dll</MtouchInterpreter> no luck

I'm unable to see logs for the app crashing in iOS in Release mode, but i have captured the logs for the app crashing on Android in Release prior to setting Optimise flag set to false if that gives any clues to a fix.

Can anyone point me in the right direction to getting this to work in iOS Release mode?

Is it possible to disable code trimming or Native AOT compiling for just this Some.External.Library.dll?

Android application is running (debug is disabled in android project properties).
> am start -D -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "com.company.app/crc64c5b56e9de2b8c8b2.MainActivity"
> Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.company.app/crc64c5b56e9de2b8c8b2.MainActivity }
> warning: Could not connect Jdwp. System.IO.InvalidDataException: Debugger response did not match expected value: 'JDWP-Handshake'
at Xamarin.AndroidTools.Debugging.Java.JdwpClient.<ConnectAsync>d__12.MoveNext() in D:\a\_work\1\s\External\androidtools\Xamarin.AndroidTools\Debugging\Java\JdwpClient.cs:line 65
at Xamarin.AndroidTools.Debugging.DebuggingExtensions.<ConnectJdwpAsync>d__8.MoveNext() in D:\a\_work\1\s\External\androidtools\Xamarin.AndroidTools\Debugging\DebuggingExtensions.cs:line 194
at Xamarin.AndroidTools.Debugging.DebuggingExtensions.<ConnectJdwpAsync>d__8.MoveNext() in D:\a\_work\1\s\External\androidtools\Xamarin.AndroidTools\Debugging\DebuggingExtensions.cs:line 198
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xamarin.AndroidTools.Debugging.DebuggingExtensions.<StartWithDebuggingAsync>d__2.MoveNext() in D:\a\_work\1\s\External\androidtools\Xamarin.AndroidTools\Debugging\DebuggingExtensions.cs:line 63
[app] Using CollectorTypeCC GC.
[app] Unexpected CPU variant for x86: x86_64.
[app] Known variants: atom, sandybridge, silvermont, goldmont, goldmont-plus, tremont, kabylake, default
[app] Not starting debugger since process cannot load the jdwp agent.
[CompatibilityChangeReporter] Compat change id reported: 171979766; UID 10199; state: ENABLED
[CompatibilityChangeReporter] Compat change id reported: 242716250; UID 10199; state: ENABLED
[ApplicationLoaders] Returning zygote-cached class loader: /system_ext/framework/androidx.window.extensions.jar
[ApplicationLoaders] Returning zygote-cached class loader: /system_ext/framework/androidx.window.sidecar.jar
[ziparchive] Unable to open '/data/app/~~tFAsc0uhin51NvyTUwMfaQ==/com.company.app-DvNiwiuBuLbpzaQHmo4MOA==/split_config.en.dm': No such file or directory
[ziparchive] Unable to open '/data/app/~~tFAsc0uhin51NvyTUwMfaQ==/com.company.app-DvNiwiuBuLbpzaQHmo4MOA==/split_config.x86_64.dm': No such file or directory
[ziparchive] Unable to open '/data/app/~~tFAsc0uhin51NvyTUwMfaQ==/com.company.app-DvNiwiuBuLbpzaQHmo4MOA==/split_config.xxhdpi.dm': No such file or directory
[app] Entry not found
[nativeloader] Configuring clns-6 for other apk /data/app/~~tFAsc0uhin51NvyTUwMfaQ==/com.company.app-DvNiwiuBuLbpzaQHmo4MOA==/base.apk:/data/app/~~tFAsc0uhin51NvyTUwMfaQ==/com.company.app-DvNiwiuBuLbpzaQHmo4MOA==/split_config.en.apk:/data/app/~~tFAsc0uhin51NvyTUwMfaQ==/com.company.app-DvNiwiuBuLbpzaQHmo4MOA==/split_config.x86_64.apk:/data/app/~~tFAsc0uhin51NvyTUwMfaQ==/com.company.app-DvNiwiuBuLbpzaQHmo4MOA==/split_config.xxhdpi.apk. target_sdk_version=35, uses_libraries=, library_path=/data/app/~~tFAsc0uhin51NvyTUwMfaQ==/com.company.app-DvNiwiuBuLbpzaQHmo4MOA==/lib/x86_64:/data/app/~~tFAsc0uhin51NvyTUwMfaQ==/com.company.app-DvNiwiuBuLbpzaQHmo4MOA==/base.apk!/lib/x86_64:/data/app/~~tFAsc0uhin51NvyTUwMfaQ==/com.company.app-DvNiwiuBuLbpzaQHmo4MOA==/split_config.en.apk!/lib/x86_64:/data/app/~~tFAsc0uhin51NvyTUwMfaQ==/com.company.app-DvNiwiuBuLbpzaQHmo4MOA==/split_config.x86_64.apk!/li
[GraphicsEnvironment] Currently set values for:
[GraphicsEnvironment]   angle_gl_driver_selection_pkgs=[]
[GraphicsEnvironment]   angle_gl_driver_selection_values=[]
[GraphicsEnvironment] ANGLE GameManagerService for com.company.app: false
[GraphicsEnvironment] com.company.app is not listed in per-application setting
[GraphicsEnvironment] Neither updatable production driver nor prerelease driver is supported.
[DOTNET] AndroidCryptoNative_InitLibraryOnLoad: jint AndroidCryptoNative_InitLibraryOnLoad(JavaVM *, void *) in /__w/1/s/src/native/libs/System.Security.Cryptography.Native.Android/pal_jni.c
[DOTNET] GetOptionalClassGRef: optional class com/android/org/conscrypt/OpenSSLEngineImpl was not found
[AppCompatDelegate] Checking for metadata for AppLocalesMetadataHolderService : Service not found
[CompatibilityChangeReporter] Compat change id reported: 171228096; UID 10199; state: ENABLED
[TabLayout] MODE_SCROLLABLE + GRAVITY_FILL is not supported, GRAVITY_START will be used instead
[CompatibilityChangeReporter] Compat change id reported: 210923482; UID 10199; state: ENABLED
[CompatibilityChangeReporter] Compat change id reported: 237531167; UID 10199; state: DISABLED
[Choreographer] Skipped 238 frames!  The application may be doing too much work on its main thread.
[Gralloc4] mapper 4.x is not supported
[Choreographer] Skipped 91 frames!  The application may be doing too much work on its main thread.
[app] Explicit concurrent copying GC freed 20789(1826KB) AllocSpace objects, 1(20KB) LOS objects, 49% free, 4348KB/8696KB, paused 1.577ms,65us total 25.625ms
[ProfileInstaller] Installing profile for com.company.app
[RippleDrawable] The RippleDrawable.STYLE_PATTERNED animation is not supported for a non-hardware accelerated Canvas. Skipping animation.
[WindowOnBackDispatcher] sendCancelIfRunning: isInProgress=falsecallback=android.view.ViewRootImpl$$ExternalSyntheticLambda17@9fe923
[monodroid-assembly] Shared library 'liblog' not loaded, p/invoke '__android_log_print' may fail
[DOTNET] info: Some.App.Application.ViewModels.Auth.LoginViewModel[100]
[DOTNET]       test
[WindowOnBackDispatcher] OnBackInvokedCallback is not enabled for the application.
[WindowOnBackDispatcher] Set 'android:enableOnBackInvokedCallback="true"' in the application manifest.
[Choreographer] Skipped 86 frames!  The application may be doing too much work on its main thread.
[com.company.app]  Error: 0 :
[com.company.app] Exception: ConstructorContainsNullParameterNames, System.Collections.Generic.KeyValuePair`2[System.String,System.String]
[MaterialButton] MaterialButton manages its own background to control elevation, shape, color and states. Consider using backgroundTint, shapeAppearance and other attributes where available. A custom background will ignore these attributes and you should consider handling interaction states such as pressed, focused and disabled
[Choreographer] Skipped 121 frames!  The application may be doing too much work on its main thread.
[AutofillManager] notifyViewEnteredForFillDialog:1073741825
[AutofillManager] notifyViewEnteredForFillDialog:1073741826
[app] Explicit concurrent copying GC freed 10910(521KB) AllocSpace objects, 12(408KB) LOS objects, 49% free, 4719KB/9438KB, paused 888us,55us total 15.019ms
[app] Explicit concurrent copying GC freed 2276(111KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 4655KB/9311KB, paused 8.364ms,77us total 77.424ms
[app] Explicit concurrent copying GC freed 2938(122KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 4677KB/9355KB, paused 1.120ms,87us total 32.517ms
[app] Explicit concurrent copying GC freed 5508(222KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 4694KB/9389KB, paused 1.376ms,348us total 62.517ms
[app] Explicit concurrent copying GC freed 6143(222KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 4696KB/9392KB, paused 1.261ms,70us total 33.304ms
[app] Explicit concurrent copying GC freed 6061(222KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 4697KB/9395KB, paused 570us,224us total 52.652ms
[DOTNET]          at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()
[DOTNET]          at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()
[DOTNET]          at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()
[DOTNET]          at System.Text.Json.JsonSerializerOptions.GetTypeInfoForRootType(Type , Boolean )
[DOTNET]          at System.Text.Json.JsonSerializerOptions.TryGetPolymorphicTypeInfoForRootType(Object , JsonTypeInfo& )
[DOTNET]          at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[System.Object, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Serialize(Utf8JsonWriter , Object& , Object )
[DOTNET]          at System.Text.Json.JsonSerializer.WriteString[Object](Object& , JsonTypeInfo`1 )
[DOTNET]          at System.Text.Json.JsonSerializer.Serialize[Object](Object , JsonSerializerOptions )
[DOTNET]          at Some.External.Library.Logging.EventHub.EventHubClientHttp.<>c.<Some.External.Library.Logging.EventHub.IEventHubClient.SendBatchAsync>b__6_0(Object b)
[DOTNET]          at System.Linq.Enumerable.ArraySelectIterator`2[[System.Object, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[<>f__AnonymousType0`1[[System.String, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], Some.External.Library, Version=2024.255.21927.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
[DOTNET]          at System.Linq.Enumerable.<ToArray>g__EnumerableToArray|301_0[<>f__AnonymousType0`1](IEnumerable`1 )
[DOTNET]          at System.Linq.Enumerable.ToArray[<>f__AnonymousType0`1](IEnumerable`1 )
[DOTNET]          at Some.External.Library.Logging.EventHub.EventHubClientHttp.Some.External.Library.Logging.EventHub.IEventHubClient.SendBatchAsync(IEnumerable`1 batch)
[DOTNET]          at Some.External.Library.Logging.EventHub.EventHubLogger.SendBufferedBatch(Object[] buffer)
[DOTNET] crit: Some.App.Application.App[701]
[DOTNET]       ConstructorContainsNullParameterNames, System.Collections.Generic.KeyValuePair`2[System.String,System.String]
[DOTNET]       System.NotSupportedException: ConstructorContainsNullParameterNames, System.Collections.Generic.KeyValuePair`2[System.String,System.String]
[DOTNET]          at System.Text.Json.ThrowHelper.ThrowNotSupportedException_ConstructorContainsNullParameterNames(Type )
[DOTNET]          at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.PopulateParameterInfoValues(JsonTypeInfo , NullabilityInfoContext )
[DOTNET]          at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateTypeInfoCore(Type , JsonConverter , JsonSerializerOptions )
[DOTNET]          at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateJsonTypeInfo(Type , JsonSerializerOptions )
[DOTNET]          at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions )
[DOTNET]          at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type )
[DOTNET]          at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context)
[DOTNET]       --- End of stack trace from previous location ---
[DOTNET]          at System.Text.Json.JsonSerializerOptions.CachingContext.CacheEntry.GetResult()
[DOTNET]          at System.Text.Json.JsonSerializerOptions.CachingContext.GetOrAddTypeInfo(Type , Boolean )
[DOTNET]          at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Nullable`1 , Boolean , Boolean )
[DOTNET]          at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
[DOTNET]          at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,834 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,208 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 34,556 Reputation points Microsoft Vendor
    2025-01-16T05:56:41.2+00:00

    Hello,

    Is it possible to disable code trimming or Native AOT compiling for just this Some.External.Library.dll?

    Yes, you could try to specify assemblies that should be excluded from the trimming process, while allowing other assemblies to be trimmed. Please see Trim a .NET MAUI app - .NET MAUI | Microsoft Learn

    <ItemGroup>
      <TrimmerRootAssembly Include="Some.External.Library" />
    </ItemGroup>
    

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Muhammad Sharif Uddin 0 Reputation points
    2025-01-17T10:24:07.1733333+00:00

    Thanks for your help, I have manged to resolve the issue with the following settings below

    <UseInterpreter>true</UseInterpreter>
    <MtouchInterpreter>all</MtouchInterpreter>
    <MtouchLink>None</MtouchLink>
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.