[release/6.0] Fix Culture creation regression when using invalid names on Windows #57853
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #57310
Backport of #57754 to release/6.0
/cc @tarekgh
Customer Impact
This change is fixing a regression from .NET 5.0. The problem happens when trying to create a CultureInfo object using culture names that Windows don't allow. If any app take dependency on such behavior will be broken. The issue is already reported by external community member. Here are more details about the change:
This regression occurred during the code refactoring work done to optimize the globalization data size and WASM support.
Although this fix is addressing the regression, it fixes another issue I have discovered during the investigation. Here is what the change is doing:
CultureData.Windows.cs
, the conditionShouldUseUserOverrideNlsData
is wrong to use. The reason is this part of the code is not concerned about the user overrides. Even the user overrides flag is not initialized yet at this stage.GetLocaleInfoEx
that help validate the culture name. That is what we have done in .NET 5.0 too.IcuLocaleData.cs
, there was a bug that caused not finding the proper culture name mapping to our data because the culture name containing characters like underscore character_
.Testing
I have run manual testing and passing all our regression tests. Also, I have added more tests to cover the gap of the scenario of this issue.
Risk
Is not high as the fix is scoped and shouldn't affect other culture scenarios.