You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
The text was updated successfully, but these errors were encountered:
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
Hosting Model (is this issue happening with a certain hosting model?):
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.
The text was updated successfully, but these errors were encountered: