Tewr/BlazorWorker

Only globalization-invariant mode is supported in the WorkerService

semyonc opened this issue · 5 comments

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)

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

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

module.onRuntimeInitialized = () =>
MONO.mono_wasm_setenv('DOTNET_SYSTEM_GLOBALIZATION_INVARIANT', '1');

What do you think?

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

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

Tewr commented

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.