Repository navigation
Description
Describe the bug
As part of fixing #81 (late failure on detecting globalization-invariant mode), code was added to detect this situation early and give a descriptive error. Unfortunately this code (which uses CultureInfo.GetCulture("en-US").EnglishName) is broken from .NET 6 onward, as a result of this breaking change which makes asking for specific cultures a runtime error. As a result, attempting to open a connection in globalization-invariant mode now produces this message instead:
Unhandled exception. System.Globalization.CultureNotFoundException:
Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-us is an invalid culture identifier.
This is still better than nothing as it fails early and points the user in the right direction, but not as clear as it could be and potentially confusing if the user isn't actually using the en-US culture at all.
To reproduce
.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.0" />
</ItemGroup>
</Project>Main.cs:
class Program { static void Main() => new Microsoft.Data.SqlClient.SqlConnection().Open(); }Expected behavior
Ideally the output should be what it was when targeting netcoreapp31 or earlier:
Unhandled exception. System.NotSupportedException: Globalization Invariant Mode is not supported.
Additional context
There appears to be no public API in the CLR for detecting this mode -- something which has bitten other library authors as well, e.g. this SO issue. The proposed workarounds include a lot of code for what should conceptually be a simple check, so it may be worth petitioning the core team with an API proposal and leaving this issue until that's sorted. This has been done at runtime#81429.
Activity
lcheunglci commentedon Jan 31, 2023
Hi @jeroen-mostert , thanks for bringing this issue to our attention and providing the repro steps. We'll see what we can do and we'll get back to you soon.
lcheunglci commentedon Jan 31, 2023
This is by design as you mentioned in #81.
David-Engel commentedon Jan 31, 2023
Reopening. We should fix the behavior to return the previous (clearer) error message. Not a high priority, though.
Varorbc commentedon May 11, 2023
.net 8 will set
InvariantGlobalizationenable by default, is it possible to consider a redesign?Frulfump commentedon Oct 15, 2025
Is that still the case? There's a diagnostic being discussed in #2043