Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry.Maui package causes Unhandled Exception in .NET MAUI WinUI application #3706

Open
luminixinc opened this issue Oct 23, 2024 · 9 comments

Comments

@luminixinc
Copy link

Package

Sentry.Maui

.NET Flavor

.NET

.NET Version

8.0

OS

Windows

SDK Version

4.12.1

Self-Hosted Sentry Version

No response

Steps to Reproduce

We have created a reduced test case that demonstrates the problem. See https://github.com/luminixinc/NetMauiWinUI_SentryMaui

Expected Result

I expected to be able to run the simple application and see the MainPage with waving dotnet bot and the extra button that calls SentrySdk.CaptureMessage

Actual Result

Unhandled exception {"Could not load file or assembly 'WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'. The system cannot find the file specified.":"WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709"}

See reduced test case that demonstrates the issue at https://github.com/luminixinc/NetMauiWinUI_SentryMaui

@bricefriha
Copy link
Contributor

@luminixinc thanks for reporting this.

I ran the app from the repo you provided. Unfortunately, I'm unable to reproduce the issue.
I can run the app, click the button, and see the message captured on Sentry without exception.
Image

I tried with both our DSN and yours (you should be able to see the item on the issues tab on Sentry on your hand as well).

Unhandled exception {"Could not load file or assembly 'WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'. The system cannot find the file specified.":"WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709"}

Additionally, this message indicates that WinRT.Runtime is missing. So, it's unlikely related to the Sentry SDK.

Is there any other info that would help reproduce this issue?

@bricefriha bricefriha added the Question Further information is requested label Oct 24, 2024
@CyborgDE
Copy link

CyborgDE commented Nov 8, 2024

Hello,
I have the same issue with Versions greater 4.12.0.
4.12.0 is OK ...

@bricefriha
Copy link
Contributor

Thanks @CyborgDE

I'm gonna investigate further, especially on 4.12.1; if it's on this version, it may be related to #3655 according to the change logs

@jamescrosswell
Copy link
Collaborator

Thanks @CyborgDE

I'm gonna investigate further, especially on 4.12.1; if it's on this version, it may be related to #3655 according to the change logs

I don't think that change is related. WinRT.Runtime doesn't have anything to do with Utf8JsonWriter.

@jamescrosswell jamescrosswell added Needs Reproduction Bug Something isn't working and removed Question Further information is requested labels Nov 12, 2024
@rogerbriggen-securiton
Copy link

rogerbriggen-securiton commented Nov 28, 2024

We have the same issue. It seems that Sentry has a dependency to WinRT.Runtime 2.1 which has its own problems. We are using MAUI 8.0.80 with default settings for Windows SDK. We use dotnet 8.0.401 SDK.

2024-11-28 15:50:03.277 +01:00 [ERR] Unhandled exception. Sender: Redacted.WinUI.App UnhandledExceptionEventArgs: System.UnhandledExceptionEventArgs { ThreadId: 1 }
System.TypeInitializationException: The type initializer for '' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'. The system cannot find the file specified.
File name: 'WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'
at WinRT.Sentry_MauiGenericHelpers.GlobalVtableLookup.InitializeGlobalVtableLookup()
at .cctor()
--- End of inner exception stack trace ---
at Redacted.MauiProgram.SetupSentry(MauiAppBuilder builder)
at Redacted.MauiProgram.CreateMauiApp() in C:\git\redacted\MauiProgram.cs:line 53
at Redacted.WinUI.App.CreateMauiApp() in C:\git\redacted\Platforms\Windows\App.xaml.cs:line 24
at Microsoft.Maui.MauiWinUIApplication.OnLaunched(LaunchActivatedEventArgs args)
at Microsoft.UI.Xaml.Application.Microsoft.UI.Xaml.IApplicationOverrides.OnLaunched(LaunchActivatedEventArgs args)
at ABI.Microsoft.UI.Xaml.IApplicationOverrides.Do_Abi_OnLaunched_0(IntPtr thisPtr, IntPtr args)

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Nov 28, 2024
@bruno-garcia
Copy link
Member

Sentry doesn't really have any dependencies. Sentry.Maui depends on Sentry.Extensions.Logging
Which depends
on Sentry which has no dependencies.

S.E.L also depends on Microsoft.Extensions.Http, Microsoft.Extensions.Logging.Configuration and Microsoft.Extensions.Configuration.Binder (on net8+)

@rogerbriggen-securiton
Copy link

Sentry doesn't really have any dependencies. Sentry.Maui depends on Sentry.Extensions.Logging Which depends on Sentry which has no dependencies.

S.E.L also depends on Microsoft.Extensions.Http, Microsoft.Extensions.Logging.Configuration and Microsoft.Extensions.Configuration.Binder (on net8+)

Nuget wise you are right. But I guess you used 8.0.404 to compile your MAUI nuget and there are dependencies.
It does not crash on my side, wenn I use 8.0.404 to compile my version, then it works with Sentry 4.13. With 8.0.401 it crashes, there a downgrade to 4.12 helps.
And you get the dependencies from here: dotnet/maui#25132

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Nov 29, 2024
@bruno-garcia
Copy link
Member

Thank you for the pointers. We'll look into this. One thing we'll do already is ping the platform version in the tfm, should help with some of the unexpected behavior we get when bumping sdk version in CI and also in the final app.

@jamescrosswell
Copy link
Collaborator

Nuget wise you are right. But I guess you used 8.0.404 to compile your MAUI nuget and there are dependencies.
It does not crash on my side, wenn I use 8.0.404 to compile my version, then it works with Sentry 4.13. With 8.0.401 it crashes, there a downgrade to 4.12 helps.

We had to bump to at least 8.0.403 for folks using Xcode 16.x.

I'm surprised downgrading to 4.12 helps however, as that change was made in the 4.12 release. @bruno-garcia I'm wondering whether there's an issue with the changelog - perhaps that workload was used to build the 4.12.1 release (not the 4.12.0 release)? I vaguely remember some issues with the build when we made that release.

In any event, if you're using Sentry 4.12+ then you need to be using version 8.0.403 or later of the MAUI workloads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: No status
Development

No branches or pull requests

6 participants