public async Task InitAsync() { if (IsInitialized) { return; } await _scriptLoader.InitScript(); Type ms = typeof(WorkerThreadMessagingProvider); Type wp = typeof(WorkerEntryPoint); (ulong callId, Task <object> task) = _messagingService.ReserveId(Id); string[] dependentAssemblyFilenames = _workerCreationConfiguration.IncludedAssemblies.Except(_workerCreationConfiguration.ExcludedAssemblied).ToArray(); await _jsRuntime.InvokeVoidAsync($"{ScriptLoader.ModuleName}.initWorker", Id, DotNetObjectReference.Create((MainThreadMessagingProvider)_messagingProvider), new WorkerInitOptions { DependentAssemblyFilenames = dependentAssemblyFilenames, CallbackMethod = nameof(MainThreadMessagingProvider.OnMessage), MessageEndpoint = $"[{ms.Assembly.GetName().Name}]{ms.FullName}:{nameof(WorkerThreadMessagingProvider.InternalOnMessage)}", InitEndpoint = $"[{wp.Assembly.GetName().Name}]{wp.FullName}:{nameof(WorkerEntryPoint.Init)}", InitCallId = callId, StartupType = typeof(T).AssemblyQualifiedName, Debug = false }); if (await task is not Message <InitializeResult> iwrm) { throw new InvalidOperationException($"Failed to init worker with id {Id}."); } IsInitialized = true; }