Tewr / BlazorWorker

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

Only globalization-invariant mode is supported in the WorkerService #67

Closed semyonc closed 2 years ago

semyonc commented 2 years ago

An attempt to get CultureInfo with System.Globalization.CultureInfo.GetCultureInfo(String name) throws exception "Only the invariant culture is supported in globalization-invariant mode" in the WorkerService (net 6.0)

semyonc commented 2 years ago

The issue is fixed by changing module.onRuntimeInitialized = () => MONO.mono_wasm_setenv('DOTNET_SYSTEM_GLOBALIZATION_INVARIANT', '1'); with the module.onRuntimeInitialized = () => { MONO.mono_wasm_setenv('DOTNET_SYSTEM_GLOBALIZATION_INVARIANT', '1'); MONO.mono_wasm_setenv('DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY', '0'); }; in the blazorWorker.js.

What's the reason of using hard-coded DOTNET_SYSTEM_GLOBALIZATION_INVARIANT = 1 in this place? See also, Culture creation and case mapping in globalization-invariant mode at the MS docs

Tewr commented 2 years ago

Hello! Thank you for your feedback.

What's the reason of using hard-coded DOTNET_SYSTEM_GLOBALIZATION_INVARIANT = 1 in this place?

The fact that it's hardcoded was overlooked when migrating these lines from the net6.0 Mono Platform:

https://github.com/dotnet/aspnetcore/blob/d9521accdbe8d463544337c3e9069e5ee9596a69/src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts#L288-L290

I started out replicating the resourceLoader but it turned out to be very complicated so I kind of dropped it but this line remained. So I agree, this is a problem, the line isn't really supposed to be there, at least not hardcoded.

Your suggestion is that I add DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY=false, OK so that's an option I guess. But if I choose between adding code and removing, I sure would go for removal of the line

https://github.com/Tewr/BlazorWorker/blob/fa076087a3c5880429c7fb28aab7db15eba69709/src/BlazorWorker/BlazorWorker.js#L95-L96

What do you think?

semyonc commented 2 years ago

I absolutely agree, it’s better if there are no specific reasons for using it. I will check in my project too and provide the feedback

semyonc commented 2 years ago

Unfortunately, it's not worked without DOTNET_SYSTEM_GLOBALIZATION_INVARIANT = 1 in my case, error at the initialization.

Tewr commented 2 years ago

I have decided to parametrize the environment variables, so it can work for you with a config similar to the one you provided. As I'm hesitant to provide a non-standard value for the DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY value.