You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.Net 5.0 Int.Parse fails parsing with negative values. #40258
@benaadams , hard to do when third party library uses the method. @tarekgh why such a braking change?
At least is <InvariantGlobalization>true</InvariantGlobalization> fisible option.
Thanks.
@eriksimonic - Outside the move to ICU, this sort of thing is always possible; you can construct/use custom cultures on windows that would have the same effect.
It might be handy to know what sort of third-party library you're using here; for instance, if you're doing data serialization/processing, you should likely be in the invariant culture anyways. Although I'd probably raise a bug with them if you can't override the culture/formatting options.
@eriksimonic, the answer of @Clockwork-Muse is correct. .NET 5.0 is by default using ICU and NLS. you have the option to switch back to NLS. but I wouldn't recommend that because NLS data can change too especially Windows working hard to converge with CLDR data which is shipped with ICU. As @Clockwork-Muse mentioned, if you want to guarantee the parsing, you should format and parse using Invariant culture.
ghost locked as resolved and limited conversation to collaborators on Dec 7, 2020
Activity
Dotnet-GitSync-Bot commentedon Aug 3, 2020
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
EgorBo commentedon Aug 3, 2020
@eriksimonic what is the current culture?
and OS?
eriksimonic commentedon Aug 3, 2020
@EgorBo
Windows 10 2004, build 19041.388
Culture is sl-SI
If I change the culture to CultureInfo.InvariantCulture, the parse works.
EgorBo commentedon Aug 3, 2020
sl-SI locale uses a slightly different negative sign 🙂
You can obtain it via
new CultureInfo("sl-SI").NumberFormat.NegativeSigneriksimonic commentedon Aug 3, 2020
@EgorBo , this works correctly in .net core 5.0 or any other, It is this a "feature"
EgorBo commentedon Aug 3, 2020
hm... indeed, 🤔
works for
net4xandnetcoreapp3.1(windows)but doesn't work for
net5(windows and *nix) andnetcoreapp3.1(*nix, ICU)benaadams commentedon Aug 3, 2020
Hasn't net5 moved to ICU on windows also?
am11 commentedon Aug 3, 2020
Yes. net5 switched to ICU library on Windows. Some cultures (e.g. en-US) work with multiple minus signs
U+002DandU+221with ICU. Apparently not the case withsl-SI. Interestingly, there was a related bug for Slovenian minus sign (U+2013), which was fixed last year in release 31: https://unicode-org.atlassian.net/browse/CLDR-10050.EgorBo commentedon Aug 3, 2020
@eriksimonic as a workaround you can define an env. variable
DOTNET_SYSTEM_GLOBALIZATION_USENLS=trueto rely on NLS instead of ICU on Windows.tarekgh commentedon Aug 3, 2020
Yes this is by design as we switched to ICU.
sl-SIis not using-as the negative sign. If you are parsing with such culture you have to provide the correct negative sign. As mentioned earlier in the discussion, to workaround it, either use different culture e.g. Invariant, or enable NLS by the config switchSystem.Globalization.UseNlshttps://docs.microsoft.com/en-us/dotnet/standard/globalization-localization/globalization-icu.benaadams commentedon Aug 3, 2020
You could also write a method that tries both
eriksimonic commentedon Aug 4, 2020
@benaadams , hard to do when third party library uses the method.
@tarekgh why such a braking change?
At least is
<InvariantGlobalization>true</InvariantGlobalization>fisible option.Thanks.
Clockwork-Muse commentedon Aug 4, 2020
@eriksimonic - Outside the move to ICU, this sort of thing is always possible; you can construct/use custom cultures on windows that would have the same effect.
It might be handy to know what sort of third-party library you're using here; for instance, if you're doing data serialization/processing, you should likely be in the invariant culture anyways. Although I'd probably raise a bug with them if you can't override the culture/formatting options.
tarekgh commentedon Aug 4, 2020
@eriksimonic, the answer of @Clockwork-Muse is correct. .NET 5.0 is by default using ICU and NLS. you have the option to switch back to NLS. but I wouldn't recommend that because NLS data can change too especially Windows working hard to converge with CLDR data which is shipped with ICU. As @Clockwork-Muse mentioned, if you want to guarantee the parsing, you should format and parse using Invariant culture.