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

WPF/WinForms Blazor WebView Exception Handling #40765

Merged
merged 1 commit into from
Mar 21, 2022

Conversation

TanayParikh
Copy link
Contributor

@TanayParikh TanayParikh commented Mar 17, 2022

WPF/WinForms Blazor WebView Exception Handling

Currently exceptions within Blazor code are not fatal to the underlying application, resulting in inconsistent behavior and a challenging debugging experience for developers.

Description

Updated exception handling mechanism to throw exceptions from the platform dispatch context instead of directly, so they can be consumed in WPF/WinForms applications using the standard AppDomain.CurrentDomain.UnhandledException API.

Other details
  • Previously the re-thrown exception was being lost and we just saw the Unhandled Exception yellow bar within the webview. This had a serialized exception stack trace with limited additional information, making debugging the error more challenging.
  • Now we're able to pass the exception along to the platform's exception handling mechanism (for WPF/WinForms)
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
{
    MessageBox.Show(text: error.ExceptionObject.ToString(), caption: "Error");
};

Helpful blogs on error handling within WPF:

Please note, this is specifically for WPF/WinForms scenarios. It's not entirely clear if there's a canonical way we can do this on MAUI yet (related discussion dotnet/maui#653).

Fixes dotnet/maui#4441

Customer Impact

Provides developers with improved insights on application errors, and increased control over exception handling. When an exception occurs, the app will crash and close, instead of remaining open in a corrupted state.

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Changes are specific to WebView for use with Blazor Hybrid. The intention of this change set is to guarantee the application DOES crash.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@TanayParikh TanayParikh requested a review from a team as a code owner March 17, 2022 21:35
@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Mar 17, 2022
@ghost ghost added this to the 6.0.x milestone Mar 17, 2022
@ghost
Copy link

ghost commented Mar 17, 2022

Hi @TanayParikh. If this is not a tell-mode PR, please make sure to follow the instructions laid out in the servicing process document.
Otherwise, please add tell-mode label.

@TanayParikh TanayParikh changed the title Update MAUI Exception Handling Update WPF/WinForms Blazor WebView Exception Handling Mar 18, 2022
@TanayParikh TanayParikh changed the title Update WPF/WinForms Blazor WebView Exception Handling WPF/WinForms Blazor WebView Exception Handling Mar 18, 2022
@mkArtakMSFT mkArtakMSFT added the Servicing-consider Shiproom approval is required for the issue label Mar 21, 2022
@ghost
Copy link

ghost commented Mar 21, 2022

Hi @TanayParikh. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge.

To learn more about how to prepare a servicing PR click here.

@mkArtakMSFT mkArtakMSFT merged commit 7eb1547 into release/6.0 Mar 21, 2022
@mkArtakMSFT mkArtakMSFT deleted the taparik/mauiExceptions branch March 21, 2022 18:34
@mkArtakMSFT mkArtakMSFT added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Mar 21, 2022
@mkArtakMSFT mkArtakMSFT modified the milestones: 6.0.x, 6.0.4 Mar 21, 2022
TanayParikh added a commit that referenced this pull request Mar 23, 2022
TanayParikh added a commit that referenced this pull request Mar 24, 2022
* Forward Port Update MAUI Exception Handling (#40765)

(cherry picked from commit 7eb1547)

* Fix usings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants