Skip to content

Exception calling Dispose on IJSInProcessObjectReference instance in Blazor WebAssembly #48280

Closed
@LostBeard

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Calling Dispose on an instance of IJSInProcessObjectReference throws an exception. Only affects Blazor WebAssembly.

Affected versions of DotNet
8.0.0-preview.3.23177.8
8.0.0-preview.4.23260.4

Expected Behavior

I expected calling Dispose to not throw an exception.

Steps To Reproduce

Code to demonstrate the bug.

var js = (IJSInProcessRuntime)host.Services.GetRequiredService<IJSRuntime>();
// get an IJSInProcessObjectReference instance
// does not matter what as long as it is a valid object
var jsRef = await js.InvokeAsync<IJSInProcessObjectReference>("caches.open", "default");
// below line throws an exception
jsRef.Dispose();

Or in a new Blazor WebAssembly project use the below code in the Program.cs

using BlazorIJSObjectRefBugTest;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.JSInterop;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

var host = builder.Build();

var js = (IJSInProcessRuntime)host.Services.GetRequiredService<IJSRuntime>();
// get an IJSInProcessObjectReference instance
// does not matter what as long as it is a valid object
var jsRef = await js.InvokeAsync<IJSInProcessObjectReference>("caches.open", "default");
// below line throws an exception
jsRef.Dispose();

await host.RunAsync();

Exceptions (if any)

blazor.webassembly.js:1 Error: Assert failed: DotNet not found while looking up DotNet.jsCallDispatcher.disposeJSObjectReferenceById
Lt @ blazor.webassembly.js:1
Qs @ dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:3
$func336 @ 00af301a:0x2144c
$func233 @ 00af301a:0x1da83
$func226 @ 00af301a:0x10e58
$func257 @ 00af301a:0x1eae2
$func3118 @ 00af301a:0xe446e
$func2442 @ 00af301a:0xbb14a
$func2448 @ 00af301a:0xbb909
$func2473 @ 00af301a:0xbdf4c
$mono_wasm_invoke_method_bound @ 00af301a:0xc4ac
Module._mono_wasm_invoke_method_bound @ dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:11
pi @ dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:3
t @ dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:3
endInvokeJSFromDotNet @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
Promise.then (async)
beginInvokeJSFromDotNet @ blazor.webassembly.js:1
Xt @ blazor.webassembly.js:1
Qs.t @ dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:3
ti @ dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:3
$func336 @ 00af301a:0x21358
$func233 @ 00af301a:0x1da83
$func226 @ 00af301a:0x10e58
$func257 @ 00af301a:0x1eae2
$func3118 @ 00af301a:0xe446e
$func2442 @ 00af301a:0xbb14a
$func2448 @ 00af301a:0xbb909
$func2473 @ 00af301a:0xbdf4c
$mono_wasm_invoke_method_ref @ 00af301a:0xc3ea
Module._mono_wasm_invoke_method_ref @ dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:11
_BlazorIJSObjectRefBugTest__entrypoint @ _BlazorIJSObjectRefBugTest__entrypoint:26
(anonymous) @ dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:3
cc @ dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:3
callEntryPoint @ blazor.webassembly.js:1
Wt @ blazor.webassembly.js:1
await in Wt (async)
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
blazor.webassembly.js:1 System.AggregateException: One or more errors occurred. (Error: Assert failed: DotNet not found while looking up DotNet.jsCallDispatcher.disposeJSObjectReferenceById
    at https://localhost:7030/_framework/dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:3:136995
    at Qs (https://localhost:7030/_framework/dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:3:137209)
    at wasm://wasm/00af301a:wasm-function[336]:0x2144c
    at wasm://wasm/00af301a:wasm-function[233]:0x1da83
    at wasm://wasm/00af301a:wasm-function[226]:0x10e58
    at wasm://wasm/00af301a:wasm-function[257]:0x1eae2
    at wasm://wasm/00af301a:wasm-function[3118]:0xe446e
    at wasm://wasm/00af301a:wasm-function[2442]:0xbb14a
    at wasm://wasm/00af301a:wasm-function[2448]:0xbb909
    at wasm://wasm/00af301a:wasm-function[2473]:0xbdf4c)
 ---> Error: Assert failed: DotNet not found while looking up DotNet.jsCallDispatcher.disposeJSObjectReferenceById
    at https://localhost:7030/_framework/dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:3:136995
    at Qs (https://localhost:7030/_framework/dotnet.8.0.0-preview.4.23259.5.omx62sfscv.js:3:137209)
    at wasm://wasm/00af301a:wasm-function[336]:0x2144c
    at wasm://wasm/00af301a:wasm-function[233]:0x1da83
    at wasm://wasm/00af301a:wasm-function[226]:0x10e58
    at wasm://wasm/00af301a:wasm-function[257]:0x1eae2
    at wasm://wasm/00af301a:wasm-function[3118]:0xe446e
    at wasm://wasm/00af301a:wasm-function[2442]:0xbb14a
    at wasm://wasm/00af301a:wasm-function[2448]:0xbb909
    at wasm://wasm/00af301a:wasm-function[2473]:0xbdf4c
   --- End of inner exception stack trace ---

.NET Version

8.0.0-preview.4.23260.4

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssembly

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions