Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

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

Open
Saquibadil opened this issue Dec 10, 2021 · 8 comments
Labels
external-hotrestart p/iOS 🍎 s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/unverified New report that has yet to be verified t/bug 🐛
Projects

Comments

@Saquibadil
Copy link

Saquibadil commented Dec 10, 2021

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 Saquibadil added s/unverified New report that has yet to be verified t/bug 🐛 labels Dec 10, 2021
@jsuarezruiz jsuarezruiz added this to New in Triage via automation Dec 13, 2021
@jsuarezruiz
Copy link
Contributor

Could you share the line where is crashing?.

@jsuarezruiz jsuarezruiz moved this from New to Needs Info in Triage Dec 13, 2021
@jsuarezruiz jsuarezruiz added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Dec 13, 2021
@jfversluis
Copy link
Member

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

@Saquibadil
Copy link
Author

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

@jfversluis
Copy link
Member

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

@philnwoha
Copy link

Any update on this?

@jreschke265
Copy link

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.

@philnwoha
Copy link

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.

@jwoeste
Copy link

jwoeste commented Aug 27, 2022

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
external-hotrestart p/iOS 🍎 s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/unverified New report that has yet to be verified t/bug 🐛
Projects
Triage
  
Needs Info
Development

No branches or pull requests

6 participants