Repository navigation
Description
Description
On WPF, BlazorWebView.DisposeAsync() calls _webviewManager.MarkAsDisposing() before disposing the page (WebViewManager.DisposeAsync -> PageContext.DisposeAsync -> renderer + DI scope). From that point WebView2WebViewManager.SendMessage returns early when _isDisposing is set, silently dropping every outgoing message.
Any IAsyncDisposable component or scoped service that awaits a JS interop call while being disposed (for example disposing an IJSObjectReference module, a very common pattern) sends a BeginInvokeJS that is dropped. The call is never answered and never faulted, so its task never completes, and BlazorWebView.DisposeAsync() never returns.
No JSDisconnectedException is raised either, so the usual "safe dispose" pattern (catch JSDisconnectedException) does not help: the await simply hangs.
Real-world case: DevExpress Blazor's scoped SafeJSRuntimeService releases its JS modules on scope disposal. Any WPF dialog hosting a DxGrid that awaits BlazorWebView.DisposeAsync() before closing hangs forever.
Captured async stack (Visual Studio, Parallel Stacks, Tasks view):
JSRuntime.InvokeAsync<> [awaiting Promise, never resolved]
JSRuntimeExtensions.InvokeVoidAsync
JSObjectReference.DisposeAsync
JsObjectReferenceExtensions.SafeDisposeAsync (third party)
JSRuntimeAccessor.DisposeAsync (third party)
SafeJSRuntimeService.DisposeAsync (third party, scoped)
DisposeAsync (service scope)
PageContext.DisposeAsync
WebViewManager.DisposeAsyncCore
WebViewManager.DisposeAsync
BlazorWebView.DisposeAsyncCore
BlazorWebView.DisposeAsync
Expected: either the page is disposed while JS is still reachable (mark as disposing only after PageContext.DisposeAsync), or JS calls made after MarkAsDisposing fail fast (e.g. JSDisconnectedException, as Blazor Server does when the circuit is gone), so disposal always completes.
Steps to Reproduce
- WPF app with a
BlazorWebViewhosting a root component. - Register a scoped service that awaits JS interop on disposal:
public sealed class JsOnDispose(IJSRuntime js) : IAsyncDisposable
{
public async ValueTask DisposeAsync()
=> await js.InvokeVoidAsync("console.log", "disposing"); // never completes
}
services.AddScoped<JsOnDispose>();- Inject
JsOnDisposein the root component so it is created in the page scope. - Close the window with
await blazorWebView.DisposeAsync();(for example fromWindow.Closing, cancelling the close and closing again afterwards). DisposeAsync()never returns.
The same happens with a component whose DisposeAsync awaits JS, when it is still in the tree at DisposeAsync time. Note that RootComponents.Clear() does not remove components beforehand: it raises a Reset with no OldItems, which HandleRootComponentsCollectionChanged treats as "nothing removed".
The snippet is derived from the captured stack; I can package it as a project if needed.
Link to public reproduction project repository
No response
Version with bug
10.0.110
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows, I was not able test on other platforms
Affected platform versions
Windows 11, Microsoft.AspNetCore.Components.WebView.Wpf 10.0.110
Did you find any workaround?
Dispose the private _webviewManager ourselves first (via reflection), while JS still answers, null the field, then call BlazorWebView.DisposeAsync(). This is the same workaround already used for #26746 (ConfigureAwait(false) disposing WebView2 off the UI thread).
var field = typeof(BlazorWebView).GetField("_webviewManager", BindingFlags.NonPublic | BindingFlags.Instance);
if (field?.GetValue(webView) is IAsyncDisposable manager)
{
await manager.DisposeAsync().ConfigureAwait(true);
field.SetValue(webView, null);
}
await webView.DisposeAsync().ConfigureAwait(true);Related: #13529 / #22496 fixed a similar disposal hang on Android only (BlazorWebView.AndroidFireAndForgetAsync), #26746.
Relevant log output
None: no exception is thrown, the task just never completes.
Activity
[WPF] Fix BlazorWebView disposal hanging when cleanup awaits JS inter…
[WPF] Fix BlazorWebView disposal hanging when cleanup awaits JS inter…
ilonatommy commentedon Oct 22, 2026
#39497 was marked as fixing this report. Closing but feel free to undo @sheiksyedm, if it's incorrect.
[WPF] Fix BlazorWebView disposal hanging when cleanup awaits JS inter…
[WPF] Fix BlazorWebView disposal hanging when cleanup awaits JS inter…
[WPF] Fix BlazorWebView disposal hanging when cleanup awaits JS inter…