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.
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: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-USculture at all.To reproduce
.csproj:
Main.cs:
Expected behavior
Ideally the output should be what it was when targeting
netcoreapp31or earlier: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.