microsoft / appcenter-sdk-dotnet

Development repository for the App Center SDK for .NET platforms, including Xamarin
Other
310 stars 141 forks source link

The app throws an exception when runs AppCenter.Start method. #1721

Closed mvegaca closed 1 year ago

mvegaca commented 1 year ago

Description

The app throws an exception when runs AppCenter.Start method.

I'm working on a Avalonia CrossPlatform Project with iOS, Android, and Desktop projects. When I initialize my AnalyticsService I run:

AppCenter.Start(GetAppId(), typeof(Analytics), typeof(Crashes)); 

GetAppId returns a APP CENTER AppId for different platforms depending on the app running platform. It Works for Android and iOS but when I run this on MacOS using the MacOS App Id the code throwns an exception.

Exception message

Message "The type initializer for 'Microsoft.AppCenter.Utils.ApplicationLifecycleHelperDesktop' threw an exception." string

Exception stacktrace

  at Microsoft.AppCenter.Utils.ApplicationLifecycleHelperDesktop..ctor()
   at Microsoft.AppCenter.ApplicationLifecycleHelper.get_Instance()
   at Microsoft.AppCenter.AppCenter..ctor()
   at Microsoft.AppCenter.AppCenter.get_Instance()
   at Microsoft.AppCenter.AppCenter.PlatformStart(String appSecret, Type[] services)
   at Microsoft.AppCenter.AppCenter.Start(String appSecret, Type[] services)
   at ProjectName.Services.AnalyticsService.Initialize() in /Users/mvega/dev/LongoMatch/longoboard/Longoboard/Longoboard.Services/AnalyticsService.cs:line 41

Development enviroment

I hope you can help me with this. Please if it's a known issue and there is some workaround let me know.

Thank you very much in advance.

mvegaca commented 1 year ago

I have created an isolated PoC App to reproduce the exception, and the error is the same. If it is helpful, I Will attach it in a zip file in this GitHub issue.

aleksandr-dorofeev commented 1 year ago

Hello, @mvegaca Thanks for getting in touch with us! It's look like a duplicate issue 1702 Also, if you have a sample app with reproduce, could you attach it?

mvegaca commented 1 year ago

Hi! This is the app, I hope it can help. AppCenterSDKCrashReproApp.zip

You should add a MacOS AppID here.

image

I must said that I finally fix it targeting the app to net7.0-macos in the csproj file but this will be a problema when I will like to run this Project in Windows.

<TargetFrameworks>net7.0-macos</TargetFrameworks>

I think that the SDK should with default configuration for Avalonia XPlat Project template.

MikhailSuendukov commented 1 year ago

The error is reproduced, and apparently it is the same as in the above issue, so I am closing this issue as a duplicate, and you can track the solution to your problem in the original issue.