Tewr / BlazorWorker

Library for creating DotNet Web Worker threads/multithreading in Client side Blazor
MIT License
392 stars 36 forks source link

Odd exception thrown in WASM-WORKER when instantiating worker service: Missing Assembly System.Net.Http #70

Closed ionican closed 2 years ago

ionican commented 2 years ago

I'm getting the following error when trying to instantiate the worker service: var service = await worker.CreateBackgroundServiceAsync<StateDataManager>();

image

This is immediately followed by:

image

The data import works fine when run conventionally 'in-line'. Not sure if this is a BlazorWorker issue or I'm doing something untoward with it.

Tewr commented 2 years ago

You must load System.Net.Http. See https://github.com/Tewr/BlazorWorker#setup-dependencies . For this specific dependency, you can use the helper method .AddHttpClient(). For any other similar errors, use the methods AddAssembliesor AddAssemblyOf<>. See the demo project for more examples.

ionican commented 2 years ago

Right thank you - in the end I needed to add a number of assemblies: var service = await worker.CreateBackgroundServiceAsync<DataLoader>( options => options .AddAssemblies("IMS36.dll", "IMS36.Shared.dll","System.Net.Http.dll","System.Net.Primitives.dll", "System.Security.Cryptography.X509Certificates.dll", "System.Diagnostics.Tracing.dll", "Microsoft.Extensions.DependencyInjection.dll") ); and I see you allude to several of them in the demo example. I'm getting a crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Sequence contains no matching element error now but I think this is probably due to an understanding deficit on my side in respect of the messaging. I'll continue to study the examples.

Tewr commented 2 years ago

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Sequence contains no matching element seems unrelated and very blazor-related. try to isolate the call to the service and the results you get from the rendering of it.

Tewr commented 2 years ago

I'm closing this. Feel free to open a new issue if you have other questions.