Skip to content

The CultureInfo named "/" might stall the dotnet process on macOS/Linux #46577

@0xced

Description

@0xced

Description

Running the following code completely stalls the dotnet process:

using System;
using System.Globalization;

var cultureInfo = CultureInfo.GetCultureInfo("/");
Console.WriteLine($"cultureInfo.Name = '{cultureInfo.Name}'");
Console.WriteLine($"cultureInfo.NativeName = '{cultureInfo.NativeName}'");
Console.WriteLine("DONE");
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
</Project>

The line cultureInfo.Name = '/' is printed but the line cultureInfo.NativeName = … is never written to the console and the process is stalled. When breaking in the debugger we can see the following stack trace:

[Native frame]
CultureData.IcuGetLocaleInfo()
CultureData.GetLocaleInfoCore()
CultureData.get_NativeLanguageName()
CultureData.get_NativeName()
CultureInfo.get_NativeName()

The native frame corresponds to the call to Interop.Globalization.GetLocaleInfoString:

bool result = Interop.Globalization.GetLocaleInfoString(localeName, (uint)type, buffer, ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY);

Configuration

  • Which version of .NET is the code running on?
    5.0.1
  • What OS and version, and what distro if applicable?
    macOS 10.15.6
  • What is the architecture (x64, x86, ARM, ARM64)?
    x64
  • Do you know whether it is specific to that configuration?
    It's probably specific to ICU-based configuration, i.e macOS and Linux.

Other information

On Windows, the culture / is not supported, a CultureNotFoundException is thrown. Since .NET 5.0 and later versions use ICU libraries for globalization functionality I was surprised that the behaviour differs between macOS and Windows when accessing the culture named /.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions