Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor Wasm Microsoft.JSInterop.JSException: Could not find 'blazorCulture.get'

$
0
0

I have followed the documentation and implemented the localization for my Blazor Wasm as 100% as in the article. Microsoft suggests to invoke js at the application start as below.

builder.Services.AddLocalization();var host = builder.Build();CultureInfo culture;var js = host.Services.GetRequiredService<IJSRuntime>();var result = await js.InvokeAsync<string>("blazorCulture.get");if (result != null){    culture = new CultureInfo(result);}else{    culture = new CultureInfo("en-US");    await js.InvokeVoidAsync("blazorCulture.set", "en-US");}CultureInfo.DefaultThreadCurrentCulture = culture;CultureInfo.DefaultThreadCurrentUICulture = culture;await host.RunAsync();

This works fine but sometimes when I open the start page, it returns a Js error telling me that

blazor.webassembly.js:1 Microsoft.JSInterop.JSException: Could not find 'blazorCulture.get' ('getBlazorCulture' was undefined).blazor.webassembly.js:1 Error: Could not find 'blazorCulture.get' ('blazorCulture.get' was undefined).

When I press contol+f5 to force reload cached data, error goes away. What could cause this problem and how can I fix it?

EDIT: Below how my Index.html Body looks like, here I suspect that since cultureget.js cultureset.js are the last, other js files loading takes longer than Blazor start although it doesnt happen always. So since blazor already started and last js files are loaded after blazor start, this error occurs. Question is is there way to ensure all js files are loaded before Blazor started? Of course quicker fix could be here to move those js right after blazor.webassembly.js.

<script src="_framework/blazor.webassembly.js"></script><script src="_content/Radzen.Blazor/Radzen.Blazor.js"></script><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script><!-- third party --><script src="https://unpkg.com/js-logger/src/logger.min.js"></script><!-- custom code --><script type="module" src="_content/logger.js"></script><script type="module" src="_content/eventHandlerUtils.js"></script> <script src="_content/cultureget.js"></script><script src="_content/cultureset.js"></script>

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>