question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FXVersion.TryParse fails to parse version on Thai culture

See original GitHub issue

Problem

Steps to reproduce, on UNIX machine:

LANG=th_TH.UTF-8  dotnet new

this will print: https://gist.github.com/DavidKarlas/29a0749d371be2858ea629a3c66d26fb

Unfortunately on Windows its not so easy to reproduce, but I have this example:

CultureInfo.CurrentCulture = new CultureInfo("th-TH");
Console.WriteLine("55.66.77.88".IndexOf("."));

Which prints 0 instead of 2. And this is where FXVersion parsing fails: https://github.com/dotnet/sdk/blob/a5bda50/src/Resolvers/Microsoft.DotNet.MSBuildSdkResolver/FXVersion.cs#L237 because it tries to parse empty string.

I just want to add this is not just dotnet new problem, similar issue can be reproduced with LANG=th_TH.UTF-8 dotnet build which will print https://gist.github.com/DavidKarlas/a16d14224ad993e71f2b45a0b2103015

And I believe it will also be problem on Windows when user has Thai(or some other similar culture set) as Windows language/culture.

Solution

Use .IndexOf('.', , StringComparison.Ordinal).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
danmoseleycommented, Sep 28, 2021

@wli3 you should enable CA1307 and CA1309 (at least locally) to look for other cases https://github.com/dotnet/docs/issues/21249

0reactions
wli3commented, Sep 29, 2021

Ah, sorry, I thought it was by design. Reopening

Read more comments on GitHub >

github_iconTop Results From Across the Web

Improving docs with regard to how existing string APIs deal ...
NET Framework versions on Windows) and ICU implement different logic in ... TryParse fails to parse version on Thai culture dotnet/sdk#21518.
Read more >
TryParse places 0 on the variable when parse fails [duplicate]
If TryParse() fails and returns false , it's not an error or exception, it means the string isn't a valid int (or whatever...
Read more >
Int32.TryParse Method (System)
The conversion fails because the string cannot contain hexadecimal digits; it must contain decimal digits only. Remarks. The TryParse method is like the...
Read more >
Parse vs TryParse in .Net - Mendel Bakaleynik - Medium
The Parse method takes a string as an argument and attempts to translate it back to the specified type. Here's what it looks...
Read more >
Char.TryParse(String, Char) Method (System)
Converts the value of the specified string to its equivalent Unicode character. A return code indicates whether the conversion succeeded or failed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found