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

Unhandled exception rendering component: Please use dedicated worker for working with JavaScript interop. See https://aka.ms/dotnet-JS-interop-threads #230

Open
SGStino opened this issue Nov 24, 2023 · 0 comments
Labels
Bug Something isn't working Triage Issue needs to be triaged

Comments

@SGStino
Copy link

SGStino commented Nov 24, 2023

Describe the bug
When using threads in a blazored application, the local storage functions break, even when called from thread 1.

To Reproduce
LocalStorage.SetItemAsStringAsync("key", "value", default);

Expected behavior
No exception and saved state.

Logs

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Please use dedicated worker for working with JavaScript interop. See https://aka.ms/dotnet-JS-interop-threads
System.InvalidOperationException: Please use dedicated worker for working with JavaScript interop. See https://aka.ms/dotnet-JS-interop-threads
   at System.Runtime.InteropServices.JavaScript.JSSynchronizationContext.AssertWebWorkerContext()
   at System.Runtime.InteropServices.JavaScript.JSFunctionBinding.BindJSFunctionImpl(String functionName, String moduleName, ReadOnlySpan`1 signatures)
   at System.Runtime.InteropServices.JavaScript.JSFunctionBinding.BindJSFunction(String functionName, String moduleName, ReadOnlySpan`1 signatures)
   at WebAssembly.JSInterop.InternalCalls.InvokeJSJson(String identifier, Int64 targetInstanceId, Int32 resultType, String argsJson, Int64 asyncHandle)
   at Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.BeginInvokeJS(Int64 asyncHandle, String identifier, String argsJson, JSCallResultType resultType, Int64 targetInstanceId)
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[IJSVoidResult](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args)
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[IJSVoidResult](String identifier, CancellationToken cancellationToken, Object[] args)
   at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, CancellationToken cancellationToken, Object[] args)
   at Blazored.LocalStorage.BrowserStorageProvider.SetItemAsync(String key, String data, CancellationToken cancellationToken)
   at Blazored.LocalStorage.LocalStorageService.SetItemAsStringAsync(String key, String data, CancellationToken cancellationToken)

Hosting Model (is this issue happening with a certain hosting model?):

  • Blazor WebAssembly WITH threads

Additional context
I suspect it has something to do with the fact that JS interop is required to be invoked from the main thread. But due to the use of ConfigureAwait(false) the thread changes to one of the threadpool.

@SGStino SGStino added Bug Something isn't working Triage Issue needs to be triaged labels Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant