Skip to content

Exception calling Dispose on IJSInProcessObjectReference instance in Blazor WebAssembly #48280

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

Closed
1 task done
LostBeard opened this issue May 17, 2023 · 2 comments · Fixed by #48287
Closed
1 task done
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Milestone

Comments

@LostBeard
Copy link
Contributor

LostBeard commented May 17, 2023

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

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label May 17, 2023
@LostBeard LostBeard changed the title Exception calling Dispose on IJSInProcessObjectReference instance Exception calling Dispose on IJSInProcessObjectReference instance in Blazor WebAssembly May 17, 2023
@mkArtakMSFT mkArtakMSFT added the feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly label May 17, 2023
@LostBeard
Copy link
Contributor Author

LostBeard commented May 17, 2023

The bug seems to arise from pull #46693. They switched from using IJSUnmarshalledRuntime to JSImport for calling "DotNet.jsCallDispatcher.disposeJSObjectReferenceById" but it fails. The JSImport attribute gives an incorrect location for the function to call.

From
"aspnetcore/src/JSInterop/Microsoft.JSInterop/src/Implementation/JSInProcessObjectReference.cs"

    [JSImport("DotNet.jsCallDispatcher.disposeJSObjectReferenceById", "blazor-internal")]
    private static partial void DisposeJSObjectReferenceById([JSMarshalAs<JSType.Number>] long id);

If switched to the below JSImport it works.

    [JSImport("globalThis.DotNet.jsCallDispatcher.disposeJSObjectReferenceById")]
    private static partial void DisposeJSObjectReferenceById([JSMarshalAs<JSType.Number>] long id);

@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label May 17, 2023
@mkArtakMSFT mkArtakMSFT added this to the 8.0-preview6 milestone May 17, 2023
LostBeard added a commit to LostBeard/aspnetcore that referenced this issue May 17, 2023
@LostBeard
Copy link
Contributor Author

LostBeard commented May 17, 2023

Just submitted pull request #48287 for it.

It is my first pull request to another repo. Constructive criticism is welcome.

MackinnonBuck added a commit that referenced this issue May 24, 2023
* Update JSInProcessObjectReference.cs

Fix for bug #48280

* Add JSObjectReferences dispose tests

---------

Co-authored-by: Mackinnon Buck <[email protected]>
github-actions bot pushed a commit that referenced this issue May 30, 2023
mkArtakMSFT pushed a commit that referenced this issue May 30, 2023
* Update JSInProcessObjectReference.cs

Fix for bug #48280

* Add JSObjectReferences dispose tests

---------

Co-authored-by: Todd T <[email protected]>
Co-authored-by: Mackinnon Buck <[email protected]>
@ghost ghost locked as resolved and limited conversation to collaborators Jun 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@MackinnonBuck @LostBeard @mkArtakMSFT and others