Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] iOS crashes on AppCenter.Start in Visual Studio 2022 using hot restart

Open Saquibadil opened this issue 3 years ago • 8 comments

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

  1. In Visual Studio 2022, create new Xamarin.Forms app for Android and iOS
  2. Install Microsoft.AppCenter.Analytics and Microsoft.AppCenter.Crashes nuget packages in all three (shared, android, iOS) projects.
  3. 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

Saquibadil avatar Dec 10 '21 15:12 Saquibadil

Could you share the line where is crashing?.

jsuarezruiz avatar Dec 13 '21 14:12 jsuarezruiz

Does it give you any logs or exception information? A stack trace maybe?

jfversluis avatar Dec 13 '21 15:12 jfversluis

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

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!

Saquibadil avatar Dec 13 '21 15:12 Saquibadil

Strange, I'm wondering if this has something to do with #14905, #14955 and the likes

jfversluis avatar Dec 15 '21 09:12 jfversluis

Any update on this?

philnwoha avatar Apr 19 '22 23:04 philnwoha

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.

jreschke265 avatar Apr 22 '22 21:04 jreschke265

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.

philnwoha avatar Apr 23 '22 01:04 philnwoha

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!

jwoeste avatar Aug 27 '22 10:08 jwoeste