Humanizer icon indicating copy to clipboard operation
Humanizer copied to clipboard

Fix CultureNotFoundException when InvariantGlobalization is enabled

Open ptupitsyn opened this issue 3 years ago • 1 comments

Fixes #1126 .

Starting with .NET 6, when InvariantGlobalization is enabled, CultureInfo constructor throws CultureNotFoundException for all cultures except invariant: https://docs.microsoft.com/en-us/dotnet/core/compatibility/globalization/6.0/culture-creation-invariant-mode

  • Handle CultureNotFoundException when creating the default formatter.
  • Skip other cultures when there was an exception for en-US.

ptupitsyn avatar Jun 25 '22 15:06 ptupitsyn

CLA assistant check
All CLA requirements met.

dnfadmin avatar Jun 25 '22 15:06 dnfadmin

Any reason for not accepting this useful PR?

ThumbGen avatar Dec 03 '22 11:12 ThumbGen

@clairernovotny @MehdiK @hazzik can we please have this merged?

gurustron avatar Feb 02 '23 20:02 gurustron

@clairernovotny @MehdiK @hazzik Would you please take a look at this PR if you've got the time?

ahmadalli avatar May 25 '23 20:05 ahmadalli

@ptupitsyn sorry for the delayed reply. can you rebase. and also add a test for this scenario

SimonCropp avatar Feb 14 '24 12:02 SimonCropp

@SimonCropp invariant globalization can only be enabled before the runtime starts: https://learn.microsoft.com/en-us/dotnet/core/runtime-config/globalization

I'm not sure how to test this scenario. Is it ok to spawn a new process?

ptupitsyn avatar Feb 19 '24 06:02 ptupitsyn

@ptupitsyn i think the best way is to add a new test project with the following

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <InvariantGlobalization>true</InvariantGlobalization>
  </PropertyGroup>

</Project>

and add a few tests to it. enough to verify the change

SimonCropp avatar Feb 19 '24 07:02 SimonCropp

Just a question: how to differentiate between culture not found due, for ex, misspelling, and globalization invariant?

hazzik avatar Feb 19 '24 07:02 hazzik

@hazzik perhaps it throws a different exception?

SimonCropp avatar Feb 20 '24 11:02 SimonCropp