IvanJosipovic / BlazorApplicationInsights

Application Insights for Blazor web applications

Home Page:https://BlazorApplicationInsights.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve the error message when the SetAuthenticatedUserContext called too early

pavel-zhur opened this issue · comments

If I call the SetAuthenticatedUserContext before the host.RunAsync(), apparently the IJsRuntime is not available for the IApplicationInsights service yet, and I'm getting this error in the console:

Error: One or more errors occurred. (Value cannot be null. (Parameter 'jsRuntime'))
    at Jn (marshal-to-js.ts:349:18)
    at Ul (marshal-to-js.ts:306:28)
    at do_icall (03bff762:0x1e5b2)
    at do_icall_wrapper (03bff762:0x19519)
    at mono_interp_exec_method (03bff762:0xb447)
    at interp_entry (03bff762:0x1c94a)
    at interp_entry_static_0 (03bff762:0x1d40e)
    at wasm_native_to_interp_System_Private_CoreLib_ThreadPool_BackgroundJobHandler (03bff762:0x2a542d)
    at mono_background_exec (03bff762:0x4eb7c)
    at e.<computed> (cwraps.ts:338:24)

Looking at this error, it is hard to guess that the workaround is to call the InitJSRuntime explicitly.
It would be nice if the error message was more meaningful and included a suggestion.