Xamarin.Forms
Xamarin.Forms copied to clipboard
[Bug] iOS crashes on AppCenter.Start in Visual Studio 2022 using hot restart
Description
I installed latest version of Visual Studio 2022 (17.0.2). Created a brand new Xamarin.Forms project. Wanted to test AppCenter Analytics and Crashes.
AppCenter.Start("android={android key};" + "ios={iOS key}", typeof(Analytics), typeof(Crashes));
Installed Microsoft.AppCenter.Analytics and Microsoft.AppCenter.Crashes nuget packages in all three (shared, android, iOS) projects.
Works fine in Android..
Crashes on this line in iOS. I am trying to debug in iPhone physical device using hot restart. When I remove the above line it works just fine.
I tried this on multiple computers but no luck.
Steps to Reproduce
- In Visual Studio 2022, create new Xamarin.Forms app for Android and iOS
- Install Microsoft.AppCenter.Analytics and Microsoft.AppCenter.Crashes nuget packages in all three (shared, android, iOS) projects.
- Add above line of code in App.xaml.cs in OnStart event
Expected Behavior
Should not crash and start appcenter so it can be used in both Android and iOS
Actual Behavior
Works fine in Android but crashes on iOS
Basic Information
- NuGet Packages: Microsoft.AppCenter.Analytics and Microsoft.AppCenter.Crashes
- Affected Devices: iPhone 6
Workaround
May be it will work if I build using Mac instead of relying on Hot Restart. Didn't try that
Could you share the line where is crashing?.
Does it give you any logs or exception information? A stack trace maybe?
@jsuarezruiz It breaks on this line AppCenter.Start("android={android key};" + "ios={iOS key}", typeof(Analytics), typeof(Crashes));
Note: This is the only line I added after creating a fresh xamarin.forms project. Besides of course installing AppCenter nuget packages.
@jfversluis
I wrapped it in a try catch block but the exception is coming as null.
here is the output it generates when I debug
Resolved pending breakpoint for 'Xamarin.HotReload.HotReloadAgent.BreakpointSendToIde(System.String)' to D:\a_work\1\s\HotReload\Source\Xamarin.HotReload.Agent\HotReloadAgent.cs:403 [0x00000]. Resolved pending breakpoint for 'Xamarin.HotReload.HotReloadAgent.BreakpointCheckpoint()' to D:\a_work\1\s\HotReload\Source\Xamarin.HotReload.Agent\HotReloadAgent.cs:398 [0x00000]. Resolved pending breakpoint at 'App.xaml.cs:24,1' to void TestXamarin1.App.OnStart () [0x00000]. Resolved pending breakpoint at 'App.xaml.cs:32,1' to void TestXamarin1.App.OnStart () [0x00031]. Thread started: #8 Thread started: #9 Thread started: #10
Right before it stops debugging it generates this warning in the output. I don't know what this means. Note: My linker behavior is set to "Don't Link"
2021-12-13 10:46:49.964 Xamarin.PreBuilt.iOS[3786:720343] Xamarin.iOS: Unable to locate assembly 'System.Collections.Immutable' (culture: '')
2021-12-13 10:46:49.965 Xamarin.PreBuilt.iOS[3786:720343] Xamarin.iOS: Unable to locate assembly 'System.Collections.Immutable' (culture: '')
2021-12-13 10:46:49.982 Xamarin.PreBuilt.iOS[3786:720343] Xamarin.iOS: Unable to locate assembly 'System.Collections.Immutable' (culture: '')
2021-12-13 10:46:49.983 Xamarin.PreBuilt.iOS[3786:720343] Xamarin.iOS: Unable to locate assembly 'System.Collections.Immutable' (culture: '')
2021-12-13 10:46:50.163 Xamarin.PreBuilt.iOS[3786:720343] Xamarin.iOS: Unable to locate assembly 'System.Runtime.CompilerServices.Unsafe' (culture: '')
2021-12-13 10:46:50.163 Xamarin.PreBuilt.iOS[3786:720343] Xamarin.iOS: Unable to locate assembly 'System.Runtime.CompilerServices.Unsafe' (culture: '')
Thank you for looking into it!
Strange, I'm wondering if this has something to do with #14905, #14955 and the likes
Any update on this?
I had this exact same issue. I was able to solve this problem by reverting my Microsoft.AppCenter packages to 4.1.0.
As of writing this, the latest version of AppCenter is 4.5.0. AppCenter 4.2.0 - 4.5.0 cause this crash with a null exception. Xamarin.Forms version is 5.0.0.2401.
So for me it turns out this only happens when debugging. When we used app center to build a release version of the app, there were no issues. So to avoid the error when debugging I added the following: ObjCRuntime.Class.ThrowOnInitFailure = false; as the first line to the "FinishedLaunching" method in AppDelegate.cs. Note that this means when debugging any crashes errors or events will not go to app center.
So for me it turns out this only happens when debugging. When we used app center to build a release version of the app, there were no issues. So to avoid the error when debugging I added the following: ObjCRuntime.Class.ThrowOnInitFailure = false; as the first line to the "FinishedLaunching" method in AppDelegate.cs. Note that this means when debugging any crashes errors or events will not go to app center.
Thank you so much for this tip! Been spending days (if not a week) to figure out what caused the crash on iOS. It would probably be a good idea for the appcenter team to look into this issue!