Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback gracefully when running on runtimes that only support the Invariant culture #70096

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi
Copy link
Member Author

@dotnet/roslyn-ide @davidwengier @dibarbet for this simple resiliency pr on some stripped down distros.

@CyrusNajmabadi
Copy link
Member Author

@genlu @dibarbet ptal.

{
// See https://github.com/microsoft/vscode-dotnettools/issues/386
// This can happen when running on a runtime that is setup for culture invariant mode only.
EnUSCultureInfo = CultureInfo.InvariantCulture;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does having this replaced in break any of the other code expecting this to be en-US? For example, the check here:

if (culture.ThreeLetterWindowsLanguageName.Equals(EnUSCultureInfo.ThreeLetterWindowsLanguageName))

That doesn't do anything strange now?

Copy link
Member

@dibarbet dibarbet Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a basic test it at least doesn't throw

Console.WriteLine(CultureInfo.InvariantCulture.ThreeLetterWindowsLanguageName);
Console.WriteLine(CultureInfo.CurrentUICulture.ThreeLetterWindowsLanguageName.Equals(CultureInfo.InvariantCulture.ThreeLetterWindowsLanguageName));

writes

IVL
False

Docs also say this (though not 100% the same)

It can be used in almost any method in the [System.Globalization](https://learn.microsoft.com/en-us/dotnet/api/system.globalization?view=net-7.0) namespace that requires a culture. The objects returned by properties such as [CompareInfo](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.compareinfo?view=net-7.0), [DateTimeFormat](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.datetimeformat?view=net-7.0), and [NumberFormat](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.numberformat?view=net-7.0) also reflect the string comparison and formatting conventions of the invariant culture.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't do anything strange now?

It may. But i don't believe that's somethign we should care/invest in. This gets us out of server crashing, which is the pri0 issue. Having slightly incorrect sorting/filtering in pattern matching on this niche platform is pri4/sev4 if it happens.

@CyrusNajmabadi CyrusNajmabadi merged commit 3888717 into dotnet:main Sep 25, 2023
24 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the cultureFallback branch September 25, 2023 19:24
@ghost ghost added this to the Next milestone Sep 25, 2023
@Cosifne Cosifne modified the milestones: Next, 17.8 P3 Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.NET Server crashing with CultureNotFoundException (en-us is an invalid culture identifier)
4 participants