Tewr / BlazorWorker

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

System.ArgumentException: The object must be a runtime Reflection object. -On Simple Service creation #82

Closed MrBalabanS closed 2 years ago

MrBalabanS commented 2 years ago

Hi All I have a simple Service

 public class MyServiceInvoker
    {
        public HttpClient HttpClient { get; }
        public MyServiceInvoker(HttpClient httpClient)
        {
            HttpClient = httpClient;
        }
        public async Task<string> InvokeService()
        {
             var github = await HttpClient.GetAsync("https://api.github.com");
            return await github.Content.ReadAsStringAsync();

        }
    }

and Im creating like this:


backgroundService = await worker.CreateBackgroundServiceAsync<MyServiceInvoker>(
                    options => options
                        .AddConventionalAssemblyOfService()
                        .AddHttpClient()
                    );

And getting following Error can post entire log if necessary

.
.
.

Uncaught Error Error: System.ArgumentException: The object must be a runtime Reflection object.
    at _convert_exception_for_method_call (https://localhost:7182/_framework/dotnet.6.0.8.vo5faaltro.js:1:180229)
    at _handle_exception_for_call (https://localhost:7182/_framework/dotnet.6.0.8.vo5faaltro.js:1:182198)
    at managed__BlazorWorker_WorkerCore_BlazorWorker_WorkerCore_MessageService_OnMessage (https://mono-wasm.invalid/managed__BlazorWorker_WorkerCore_BlazorWorker_WorkerCore_MessageService_OnMessage:17:21)
    at self.onmessage (blob:https://localhost:7182/9e8e9d46-4a60-4ace-9d66-5fd6e5bf0283:17:17)
    --- Worker.postMessage ---
    at postMessage (blob:https://localhost:7182/c7f74dc3-9c30-4a08-be00-c821a5f2ace9:296:34)
    at <anonymous> (https://localhost:7182/_framework/blazor.webassembly.js:1:3332)
    at beginInvokeJSFromDotNet (https://localhost:7182/_framework/blazor.webassembly.js:1:3306)
    at St (https://localhost:7182/_framework/blazor.webassembly.js:1:59938)
    at _mono_wasm_invoke_js_blazor (https://localhost:7182/_framework/dotnet.6.0.8.vo5faaltro.js:1:195300)
    at $func219 (undefined:1:107664)
    at $func167 (undefined:1:52830)
    at $func166 (undefined:1:48497)
    at $func2812 (undefined:1:704257)
    at $func1616 (undefined:1:457922)
    at $func1614 (undefined:1:457780)
    at $func967 (undefined:1:329349)
    at $func219 (undefined:1:107593)
    at $func167 (undefined:1:52830)
    at $func166 (undefined:1:48497)
    at $func2812 (undefined:1:704257)
    at $func1616 (undefined:1:457922)
    at $func1620 (undefined:1:459567)
    at $mono_wasm_invoke_method (undefined:1:38557)
    at Module._mono_wasm_invoke_method (https://localhost:7182/_framework/dotnet.6.0.8.vo5faaltro.js:1:219002)
    at managed__Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet (https://mono-wasm.invalid/managed__Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet:19:40)
    at invokeDotNetFromJS (https://localhost:7182/_framework/blazor.webassembly.js:1:42266)
    at g (https://localhost:7182/_framework/blazor.webassembly.js:1:1618)
    at invokeMethod (https://localhost:7182/_framework/blazor.webassembly.js:1:3791)
.
.
.

BTW I AM using the nuget package 3.1.00. The Sample in the Solution are working.

MrBalabanS commented 2 years ago

Ok my bad I had to add dependant assemblies like: "System.Net.Http.Json.dll", "System.Text.Json.dll", "System.Text.Encodings.Web.dll"