-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Document handling uncaught exceptions in WinUI 3 applications with AOT enabled #2778
Comments
Interested in the guidance. Currently I am using the snippet below, which seems to work. Is it the right way to do it?
|
What we have in Sentry 3.x is the reflection based equivalient of this:
The exception handler it wires up is a bit more convoluted. In addition to what you're doing, there's a workaround for not sending through a stack trace, in some circumstances, setting a mechanism and also flushing events in the face of an irrecoverable error... but broad strokes, it looks like what you're doing is all good. This issue (once completed) should provide a way for you to hook up the |
This WinUI stuff done with reflection was a hack originally done because stuff in .NET was broken. Did they fix this in the latest versions? |
Is this related? |
I assume so, not sure. Could we get away without the hack and just document this? Troubleshooting page: WinUI customers on version of WinUI below XYZ: ... |
I published my app with trimming enabled and just observed this potential bug:
Is this something that could be prevented on the SDK side?
Additionally, I exclude some assemblies/types from trimming, using
SDK version 4.0.0-beta.1 |
Maybe we could also take a step back and look at this from a different angle: Originally, the idea was to replace all code present in the main Sentry package that is not trimmable with a trimmable alternative. This has proven problematic in other pars, e.g. Ben.Demystifier integration, JSON serialization for old TFMs, etc. |
Not sure if I understand that statement correctly, but I was able to enable full trimming in my WinUI/WinAppSDK apps (with the |
I think this is because Sentry is trying to serialize
We can register some of the commong/foreseeable types that will need to be serialized in the default context that comes with Sentry: sentry-dotnet/src/Sentry/Internal/Extensions/JsonExtensions.cs Lines 888 to 893 in e08d4f6
In the case of the particular type reported in your error message, we can't easily do that though I don't think, since it's sealed internal (and part of an assembly we can't take a dependency on in the Sentry Core package anyway): More generally, there are an unlimited number of system and user defined exceptions that could potentially be thrown and need to be serialized, and neither the Sentry SDK maintainers nor SDK users are able to know, in advance, which exceptions might come up. Implicitly, we can only discover these things at runtime with trimming enabled. We might need a more elegant fallback mechanism when serialization fails in these circumstances. @tipa are you able to provide a minimal reproducable example of this in a demo app you could share? Or just a code snippet that will reliably reproduce the two exceptions you observed? |
In my particular case, I ran into this exception: microsoft/WindowsAppSDK#3002
The original crash was captured by Sentry correctly (from what I can see):
And for every This is an example app that also calls |
Thanks @tipa - I can see in the exception that you received in Sentry, there are a couple of blank properties ( What would you expect Sentry to be doing in this scenario? Do you expect/want to be made aware of the serialization failures or would you like to be able to turn these off? If you'd like to know about them, how would you prefer to be made aware of these? |
@jamescrosswell I don't know what data these properties would normally contain, but at least for this particular crash report I was able to identify what's causing the exception with the stack trace alone. I don't have a problem with these properties being shown as blanks or not being shown at all. But it would be great if Sentry wouldn't log the |
So digging into this I think it might be something entirely different. I tried creating/throwing an exception with a property that I knew couldn't be serialized with AOT switched on and I only get one exception coming through to Sentry. The property that can't be serialized is ignored, but no other exceptions are created. I think this might genuinely be a second exception in your case... perhaps related to this? My windows box is also fully patched so I can't use the sample you provided. 🤔 |
Thanks for investigating this problem.
The exception is logged with
just to clarify: AOT is not switched on in my app - but full trimming is (with the entire |
OK, I'll close this issue (which was related to documenting how to wire up an exception handler for WinUI applications). If anything else comes up, let's create a new issue for it. Thanks for all your feedback @tipa ! PS: Yes, I should have said Trimming (not AOT... it's the trimming bit that trips up serialization). |
Ah - I just notice that the docs have been added - will adapt my code accordingly. Also, the docs docs make the differentiation between JIT and AOT compiled apps and say that manually registering for the The docs also state Anyways, thanks so much for supporting WinUI/Trimming/AOT! |
Sorry if this doesn't belong in this thread (I can open a new issue if this is preferred), but is the manual exception setup really necessary even for trimmed apps? Isn't it possible for Sentry to just something like this in the initialization process?
|
I don't think so no. You might be able to do that from your application but not from our NuGet package. What needs wiring up is the equivalent of this: Microsoft.UI.Xaml.Application.Current.UnhandledException += WinUIUnhandledExceptionHandler; In order to do that we need to:
|
Thanks @tipa - I've created a PR to update accordingly: |
To get trimming working we had to remove some code that used reflection to automatically register an unhandled exception handler in WinUI applications, if Trimming is enabled (typically when doing AOT compilation). Further details in #2732
This means we have to document how users can send unhandled exceptions to Sentry
- getsentry/sentry-docs#8557
- getsentry/sentry-docs#8602
The text was updated successfully, but these errors were encountered: