LostBeard / SpawnDev.BlazorJS

Full Blazor WebAssembly and Javascript Interop with multithreading via WebWorkers
https://blazorjs.spawndev.com
MIT License
78 stars 6 forks source link

HttpClient not working in WebWorkers with .Net 6 #18

Closed jbrown29 closed 8 months ago

jbrown29 commented 8 months ago

Is System.Net.Http.HttpClient supported in this webworker?

I'm using .net 6.0 and am getting this exception when calling SendAsync from HttpClient.

SyncDataException: Data Sync Error VM8:3 ---> System.Net.Http.HttpRequestException: TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Illegal invocation VM8:3 ---> System.Runtime.InteropServices.JavaScript.JSException: TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Illegal invocation VM8:3 at System.Net.Http.BrowserHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) VM8:3 --- End of inner exception stack trace --- VM8:3 at System.Net.Http.BrowserHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) VM8:3 at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)

LostBeard commented 8 months ago

I just created identical .Net 6, .Net 7, and .Net 8 "Blazor WebAssembly Standalone Apps" to test HTTPClient in WebWorkers. In .Net 6 I got the same error you did. It worked correctly in .Net 7 and .Net 8.

I know fetch works in WebWorkers so I'm not sure what is causing the failure at the moment.

Thank you for letting me know about this issue. I will post back after I have a chance to investigate further.

LostBeard commented 8 months ago

I found the cause of the issue and fixed it. I have uploaded an updated Nuget package, version 2.2.17.

Thank you very much for finding this issue and reporting it.

jbrown29 commented 8 months ago

You're awesome. Thank you so much!