Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,35 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry, SqlConnec
// are not present. Throwing on open with a meaningful message helps identify the issue.
if (_cultureCheckState == CultureCheckState.Unknown)
{
_cultureCheckState = CultureInfo.GetCultureInfo("en-US").EnglishName.Contains("Invariant") ? CultureCheckState.Invariant : CultureCheckState.Standard;
// check if invariant state has been set by appcontext switch directly
if (AppContext.TryGetSwitch("System.Globalization.Invariant", out bool isEnabled) && isEnabled)
{
_cultureCheckState = CultureCheckState.Invariant;
}
else
{
// check if invariant state has been set through environment variables
string envValue = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT");
if (string.Equals(envValue, bool.TrueString, StringComparison.OrdinalIgnoreCase) || string.Equals(envValue, "1", StringComparison.OrdinalIgnoreCase))
{
_cultureCheckState = CultureCheckState.Invariant;
}
else
{
// if it hasn't been manually set it could still apply if the os doesn't have
// icu libs installed or is a native binary with icu support trimmed away
// netcore 3.1 to net5 do not throw in attempting to create en-us in inariant mode
// net6 and greater will throw so catch and infer invariant mode from the exception
try
{
_cultureCheckState = CultureInfo.GetCultureInfo("en-US").EnglishName.Contains("Invariant") ? CultureCheckState.Invariant : CultureCheckState.Standard;
}
catch (CultureNotFoundException)
{
_cultureCheckState = CultureCheckState.Invariant;
}
}
}
}
if (_cultureCheckState == CultureCheckState.Invariant)
{
Expand Down