Application.UnhandledException strips Message and StackTrace
See original GitHub issueDescribe the bug
When the Microsoft.UI.Xaml.Application.UnhandledException event is raised, the exception it captures has no stack trace, and the message has reverted to the default message for the exception. This makes it very difficult to determine the cause of an unhandled exception.
Steps to reproduce the bug
Microsoft.UI.Xaml.Application.Current.UnhandledException += (sender, e) => {
var stackTrace = e.Exception.StackTrace; // set a breakpoint and examine here
}
Then go throw an exception somewhere, such as in a button click. Set a breakpoint and debug the app.
Expected behavior
The stack trace should be populated. Instead, it is null.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.0.3
Windows app type
- UWP
- Win32
Device form factor
Desktop
Windows version
Windows 11 (21H2): Build 22000
Additional context
Testing from within VS 2022 17.3.0 Preview 1.1 from within a MAUI app.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Need to handle uncaught exception and send log file
When my app creates an unhandled exception, rather than simply terminating, I'd like to first give the user an opportunity to send a...
Read more >c# - How can we avoid showing the literal path in ...
When our in-house developed application (C#, ASP.NET) is throwing an exception, it displays a stack trace that contains path information like C ...
Read more >Application.UnhandledException Event (Windows.UI.Xaml)
The UnhandledException event arguments expose an exception object through the Exception property. However, the type, message, and stack trace of this ...
Read more >An unhandled exception occurred during the execution of ...
So start with the stack trace which will tell you the file, method, and line that caused the exception. Then you can look...
Read more >What is an Unhandled Exception, and How to Catch All C# ...
An exception is a known type of error. An unhandled exception occurs when the application code does not properly handle exceptions.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

FYI - I also tried in a UWP application and the exception comes through with all properties intact, so the issue is specific for WinUI 3.
App.UnhandledException fix will be available in Windows App SDK 1.2 Preview 2.