Skip to content

[WPF] BlazorWebView.DisposeAsync never completes when a scoped service or component awaits JS interop on disposal #39471

Closed

Description

@alexdess

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

  1. WPF app with a BlazorWebView hosting a root component.
  2. 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>();
  1. Inject JsOnDispose in the root component so it is created in the page scope.
  2. Close the window with await blazorWebView.DisposeAsync(); (for example from Window.Closing, cancelling the close and closing again afterwards).
  3. 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

  1. added
    t/bug
    on Oct 19, 2026
  2. added
    area-blazor
    feature-blazor-windesktop
    s/triaged
    partner/syncfusion
    on Oct 20, 2026
  3. added 2 commits that reference this issue on Oct 20, 2026
    ce33c7b
    965fdaf
  4. ilonatommy commented on Oct 22, 2026

    @ilonatommy
    Member

    #39497 was marked as fixing this report. Closing but feel free to undo @sheiksyedm, if it's incorrect.

  5. added 2 commits that reference this issue on Oct 25, 2026
    523734e
    5537618
  6. added a commit that references this issue on Oct 28, 2026
    b0cffba
  7. locked and limited conversation to collaborators on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-blazorfeature-blazor-windesktoppartner/syncfusions/triagedt/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions