Skip to content

Detecting globalization-invariant mode fails #1913

Closed

Description

@jeroen-mostert

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

  1. lcheunglci commented on Jan 31, 2023

    @lcheunglci
    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.

  2. lcheunglci commented on Jan 31, 2023

    @lcheunglci
    Contributor

    This is by design as you mentioned in #81.

  3. David-Engel commented on Jan 31, 2023

    @David-Engel
    Contributor

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

  4. added
    Up-for-Grabs 🙌
    and removed on Jan 31, 2023
  5. Varorbc commented on May 11, 2023

    @Varorbc

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

  6. Frulfump commented on Oct 15, 2025

    @Frulfump

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

    Is that still the case? There's a diagnostic being discussed in #2043

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Up-for-Grabs 🙌

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions