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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The following contains a description of each sub-directory in the `Components` d
- `Server`: Contains the implementation for WASM-specific extension methods and the launch logic for the debugging proxy
- `WebAssembly`: Contains WebAssembly-specific implementations of the renderer, HostBuilder, etc.
- `WebAssembly.Authentication`: Contains the WASM-specific implementations
- `WebView`: Contains the source files to support [Blazor Hybrid](https://github.com/dotnet/maui/tree/main/src/BlazorWebView) within [`dotnet/maui`](https://github.com/dotnet/maui). Changes in this project can be tested with `dotnet/maui` following [this guide](https://github.com/dotnet/maui/wiki/Blazor-Desktop#aspnet-core).

## Development Setup

Expand Down
5 changes: 5 additions & 0 deletions src/Components/WebView/WebView/src/IpcSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.JSInterop;
Expand Down Expand Up @@ -62,8 +63,12 @@ public void SendByteArray(int id, byte[] data)

public void NotifyUnhandledException(Exception exception)
{
// Send the serialized exception to the WebView for display
var message = IpcCommon.Serialize(IpcCommon.OutgoingMessageType.NotifyUnhandledException, exception.Message, exception.StackTrace);
_dispatcher.InvokeAsync(() => _messageDispatcher(message));

// Also rethrow so the AppDomain's UnhandledException handler gets notified
_dispatcher.InvokeAsync(() => ExceptionDispatchInfo.Capture(exception).Throw());
}

private void DispatchMessageWithErrorHandling(string message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.ExceptionServices;
using System.Text.Json;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.AspNetCore.Components.Web;
Expand Down Expand Up @@ -38,9 +37,6 @@ protected override void HandleException(Exception exception)
{
// Notify the JS code so it can show the in-app UI
_ipcSender.NotifyUnhandledException(exception);

// Also rethrow so the AppDomain's UnhandledException handler gets notified
ExceptionDispatchInfo.Capture(exception).Throw();
}

protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)
Expand Down