[release/9.0] Prevent unnecessary debugger stops for user-unhandled exceptions in Blazor apps with Just My Code enabled #58573
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prevent unnecessary debugger stops for user-unhandled exceptions in Blazor apps with Just My Code enabled
Improve usage of the new
[DebuggerDisableUserUnhandledExceptions]
andDebugger.BreakForUserUnhandledException(ex)
APIs to prevent unnecessarily repeated debugger stops for the same user-unhandled exceptions in Blazor apps with Just My Code enabled.Description
This is a follow up to #57148 which I've made after testing Visual Studio's treatment of
NavigationExceptions
when debugging withjust my code
enabled. The intent was to ensure thatNavigationExceptions
that get handled properly by Blazor do not get treated as user-unhandled exceptions. Unfortunately, this didn't fully work because the debugger does not follow exceptions through multiple try-catch blocks. For example:Sample code demonstrating what the debugger does and does not stop for
This caused the debugger to treat most
NavigationException
's as user-unhandled exceptions, because the method with[DebuggerDisableUserUnhandledExceptions]
was too far down the stack with multiple try/catch blocks in between. And in some cases, the debugger would stop for exceptions at a try/catch boundary and then extraneously stop again for the same exception because of callsDebugger.BreakForUserUnhandledException(ex)
.I used the
Redirect*.razor
pages in https://github.com/halter73/DebuggerDisableUserUnhandledExceptions/tree/nav/BlazorApp1/Components/Pages and https://github.com/halter73/DebuggerDisableUserUnhandledExceptions/tree/throw/BlazorApp1/Components/Pages to test these changes.@gregg-miskelly
Customer Impact
Without this change, Blazor developers with Just My Code enabled will sometimes see the debugger stop repeatedly for the same user-unhandled exception. They might also see the debugger stop for some
NavigationExceptions
which are a normal part of Blazor's operation when theNavigationManager
is used during prerendering.Regression?
Risk
Previously, the debugger would not stop at all for these user-unhandled exceptions. Breaking for Async User-Unhandled exceptions in the Visual Studio Debugger in async code is new in .NET 9.
If exceptions happen to be common in a given developer's workflow, they can easily disable breaking for user-unhandled exceptions either in general or on a per exception type basis to get the old behavior of never stopping for user-unhandled exceptions.
Verification
Packaging changes reviewed?