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

Detecting globalization-invariant mode fails #1913

Closed
jeroen-mostert opened this issue Jan 31, 2023 · 4 comments · Fixed by #1917
Closed

Detecting globalization-invariant mode fails #1913

jeroen-mostert opened this issue Jan 31, 2023 · 4 comments · Fixed by #1917
Labels
🙌 Up-for-Grabs Anyone interested in working on it can ask to be assigned

Comments

@jeroen-mostert
Copy link

jeroen-mostert commented Jan 31, 2023

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.

@lcheunglci
Copy link
Contributor

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 lcheunglci added By Design By design and removed untriaged labels Jan 31, 2023
@lcheunglci
Copy link
Contributor

This is by design as you mentioned in #81.

@David-Engel
Copy link
Contributor

Reopening. We should fix the behavior to return the previous (clearer) error message. Not a high priority, though.

@Varorbc
Copy link

Varorbc commented May 11, 2023

.net 8 will set InvariantGlobalization enable by default, is it possible to consider a redesign?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙌 Up-for-Grabs Anyone interested in working on it can ask to be assigned
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants