Raygun4Maui throws ArgumentNullException in Release build (Android and iOS)
MT
Posted on
Jul 31 2024
I'm using Raygun4Maui for both Android and iOS. It works fine in Debug mode but throws the following errors in Release build.
I wonder if Linker settings cause it or anything else?
iOS release setting: (Default settings for android)
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
<EnableAssemblyILStripping>false</EnableAssemblyILStripping>
<UseInterpreter>true</UseInterpreter>
<NoSymbolStrip>true</NoSymbolStrip>
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
<CodesignProvision>Automatic</CodesignProvision>
<CodesignKey>iPhone Distribution</CodesignKey>
</PropertyGroup>
Debug.WriteLine($"Unable to signin: {ex.Message}");
await RaygunMauiClient.Current.SendInBackground(ex);
[DOTNET] Android Unhandled Exception: System.ArgumentNullException: ArgumentNull_Generic Arg_ParamName_Name, key
[DOTNET] at System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Mindscape.Raygun4Net.Diagnostics.PEDebugInformation, Mindscape.Raygun4Net.NetCore.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=d595e487e4f9f950]].TryInsert(String key, PEDebugInformation value, InsertionBehavior behavior)
[DOTNET] at System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Mindscape.Raygun4Net.Diagnostics.PEDebugInformation, Mindscape.Raygun4Net.NetCore.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=d595e487e4f9f950]].Add(String key, PEDebugInformation value)
[DOTNET] at System.Linq.Enumerable.ToDictionary[PEDebugInformation,String](IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
[DOTNET] at System.Linq.Enumerable.ToDictionary[PEDebugInformation,String](IEnumerable`1 source, Func`2 keySelector)
[DOTNET] at Mindscape.Raygun4Net.RaygunErrorMessageBuilder.GetDebugInfoForStackFrames(IEnumerable`1 frames)
[DOTNET] at Mindscape.Raygun4Net.RaygunErrorMessageBuilder.Build(Exception exception)
[DOTNET] at Mindscape.Raygun4Net.RaygunMessageBuilder.SetExceptionDetails(Exception exception)
[DOTNET] at Mindscape.Raygun4Net.RaygunClientBase.BuildMessage(Exception exception, IList`1 tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo, Action`1 customiseMessage)
[DOTNET] at Raygun4Maui.RaygunMauiClient.SendInBackground(Exception exception, IList`1 tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo)
Panos Patros
Raygun
Posted on
Jul 31 2024
Hi MT,
Thanks for reaching out!
Can you provide with some information to help us replicate this issue?
- From the stack trace, I assume this appeared in Android but did it also happen in iOS?
- For Android, did this happen on the Visual Studio emulator or what exact platform?
- The exception
ex
you are sending in background, is one created by a catch or did you instantiated yourself? - Anything else you think we'll need to know about, feel free to add it in!
I'm looking forward to get you up and running as soon as possible, and once again, thanks for reporting this to us!
Dr. Panos Patros, CPEng, VP of Engineering, Raygun
MT
Posted on
Jul 31 2024
Thanks for the response.
- Yes, it happened on both Android and iOS devices
- It was from an Android phone (Galaxy S21 running Android 14). I also got the same error from iPhone 15 Pro (17.5.1) - Device/Crash log. All physical devices.
- I tested both, with manually created simple new HttpException("Testing"), or with airplane mode on the "No internet connection" exception, and both crashed the app. It explains why we received crash info from both Apple store/Google play, but no errors on Raygun side.
Besides iOS release build settings in csproj from previous post, there is one more Trimmer option below.
<ItemGroup> <TrimmerRootAssembly Include="System.Collections.Immutable" RootMode="library" />
Panos Patros
Raygun
Posted on
Aug 01 2024
Thanks MT. We'll work to replicate on our end and get back to you!
Panos
Panos Patros
Raygun
Posted on
Aug 01 2024
Hi again MT,
In your project's .csproj settings, are debug symbols enabled for release mode and the type set to portable?
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
</PropertyGroup>
EDIT: And can you also confirm if your application crashes or just logs these errors without crashing?
MT
Posted on
Aug 01 2024
Hi
I didn't enable DebugSymbols
After I realized Raygun caused the crash, I added additional code for handling unhandled exceptions across different platforms besides [options.RaygunSettings.CatchUnhandledExceptions = true;], now the app doesn't crash but Raygun doesn't work either. The error is now caught by UnhandledException log, or of course a try-catch around [RaygunMauiClient.Current.SendInBackground(ex);] prevents crashing too.
[DOTNET] LogRaygunException Exception: ArgumentNull_Generic Arg_ParamName_Name, key
MT
Posted on
Aug 01 2024
Well, actually, the iOS unhandled exception (AppDomain.CurrentDomain.UnhandledException) couldn't prevent the app from crashing. unless we try-catch every SendInBackground(ex).
iOS Unhandled Exception: System.ArgumentNullException: ArgumentNullGeneric ArgParamName_Name, key
at System.Linq.Enumerable.ToDictionary[PEDebugInformation,String](IEnumerable1 source, Func
2 keySelector)
at Mindscape.Raygun4Net.RaygunErrorMessageBuilder.GetDebugInfoForStackFrames(IEnumerable1 frames)
at Mindscape.Raygun4Net.RaygunErrorMessageBuilder.Build(Exception exception)
at Mindscape.Raygun4Net.RaygunMessageBuilder.SetExceptionDetails(Exception exception)
at Mindscape.Raygun4Net.RaygunClientBase.BuildMessage(Exception exception, IList
1 tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo, Action1 customiseMessage)
at Raygun4Maui.RaygunMauiClient.SendInBackground(Exception exception, IList
1 tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo)
at App.ViewModel.LoginViewModel.SignInAsync()
at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle)
at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
Panos Patros
Raygun
Posted on
Aug 01 2024
Thanks MT, this information will help us replicate and resolve this issue. We'll keep you informed in our progress and hopefully, we can resolve this issue quickly for you.
MT
Posted on
Aug 01 2024
Update:
if I set the linker to None for iOS, it works fine in the release build, but we can't publish the app with None
<MtouchLink>None</MtouchLink>
I haven't tested android yet, but I assume it's the same trimmer issue, the lib is not trimmer-safe, the trimmer ends up removing too much
<RunAOTCompilation>False</RunAOTCompilation>
<PublishTrimmed>False</PublishTrimmed>
Panos Patros
Raygun
Posted on
Aug 01 2024
Hi MT,
The team is looking into this and we'll be getting back to you with updates and/or clarifications.
Panos
Miguel Beltran
Posted on
Aug 02 2024
Hi MT,
looking into this now, my understanding is that this is an error in this method https://github.com/MindscapeHQ/raygun4net/blob/b6fdd23016e9bc28a1077343f2d30c68ccb7fc43/Mindscape.Raygun4Net.Core/Builders/RaygunErrorMessageBuilder.cs#L171-L190 when it tries to get the debug information from the Exception stack trace.
I still need to find why this code fails, but I believe some debug information is not available (e.g. stripped) in release builds and so that causes the crash.
I will keep you informed with what we find.
There is also the setting <MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>.
Have you tried this one as well and got similar results?
MT
Posted on
Aug 02 2024
Hi, Thanks for looking into this.
I've also been testing the code for the last two days, with <MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
as well.
For iOS: it crashes the app immediately in the release build regardless of the exception type, <MtouchLink>None</MtouchLink>
fixes the issue. I opened the issue on MAUI side, they also believe it's a trimmer issue, and suggested me check with raygun to make it trimmer-safe. I was trying to add trimmed dll/assembly back via TrimmerRootAssembly or linker.xml, but was unsuccessful
For Android: Actually, it works fine in release mode with regular exceptions like API errors or simple new HttpRequestException("Testing")
. However, it throws System.ArgumentNullException
when the device is not connected to the internet (Airplane mode without wifi), It functions properly again once the internet connection is restored but keeps throwing unhandled exceptionTaskExceptionHolder_UnhandledException(ArgumentNull_Generic Arg_ParamName_Name, key)
Hope it helps.
Thanks
Miguel Beltran
Posted on
Aug 05 2024
Hello, I managed to get the same exception that you had.
I need to investigate more, but I used the Sample project in https://github.com/MindscapeHQ/raygun4maui/tree/master/Raygun4Maui.SampleApp and compiled it for Release using dotnet publish -f net8.0-android -c Release
.
The issue seems to start in Raygun4Maui.RaygunMauiClient+<SendInBackground>
as your provided stack trace also shows.
I'll keep you posted with what I find.
Miguel Beltran
Posted on
Aug 06 2024
Hi MT,
Letting you know that we have identified the cause of the issue and a package release with the fix is on the way.
MT
Posted on
Aug 06 2024
Great, thanks for looking into this.
Reilly Oldham
Raygun
Posted on
Aug 06 2024
Hi MT,
I've released a pre-release version of 2.1.2 (2.1.2-pre-1) that should fix this issue, could you try out this new version to confirm your issue is resolved? Once we have that confirmed we'll do the full release.
Kind Regards, Reilly.
MT
Posted on
Aug 06 2024
Hi
it works. No more errors/crashing in the release build.
Reilly Oldham
Raygun
Posted on
Aug 06 2024
Hi MT,
That's great! Thanks for confirming. I've released the full version now.
On a side note, I noticed that you've not enabled Portable PDBs. We've recently added support for this and it allows you to get more meaningful stack traces after trimming and other obfuscation techniques.
You can read more about it here if you're interesting in trying it out.
Kind Regards, Reilly.
MT
Posted on
Aug 07 2024
Thanks, I've enabled portable PDBs