Tests in PerformanceTrackerServiceTests fail when the current English language culture uses a different number format #39248
Labels
Area-Infrastructure
Contributor Pain
The issue impedes progress for project collaborators.
help wanted
The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone
When running the included tests on my Windows 10 machine, which has its display language set to English (United States) and its regional settings set to English (Sweden) (en-SE), four of the five tests in the
PerformanceTrackerServiceTests
class fail with the message "System.InvalidOperationException : Sequence contains no elements".Digging a bit deeper shows that the cause of the exception is a section of code in the
PerformanceTrackerServiceTests.CreateMatrix()
method which tries to parse numeric values like7.0
as doubles and fails to do so because the en-SE culture has its decimal separator set to a comma and not a period.The format provider used to parse the numbers is resolved via
EnsureEnglishUICulture.PreferredOrNull
, which returns null ifCultureInfo.CurrentUICulture.Name
starts with "en" andCultureInfo.InvariantCulture
otherwise. The intention seems to be to always try to fall back to the current culture if it appears to be a common English language culture like en-US or en-UK that have a lot of formatting settings in common, but this doesn't always work when the current culture is en-SE or some other less common culture.I have fixed this issue locally by simply forcing the use of
CultureInfo.InvariantCulture
when parsing the numeric values in these particular tests, but I think it could also be worth looking intoEnsureEnglishUICulture.PreferredOrNull
and maybe restricting it to a strict subset of English language cultures that are known to work. Let me know if you would like me to submit my proposed changes as a pull request.The text was updated successfully, but these errors were encountered: