Skip to content

Globalization Invariant Mode is not works as expected when running on Alpine .NET SDK image #6838

@filzrev

Description

@filzrev

Describe the bug

On Alpine .NET SDK image.
Application that using Globalization Invariant Mode don't works as expected.
(Setting is overwritten by environment variable that set by Alpine image)

Which .NET image(s) are you using?

mcr.microsoft.com/dotnet/sdk:9.0-alpine3.22-amd64

Steps to reproduce

  1. Create Console Application with following setting
  • Framework: .NET 8.0
  • Enable container support: Checked
  • Container OS: Linux
  • Container build type: Dockerfile
  1. Switch to Release configuration
  2. Add following setting to csproj
    <InvariantGlobalization>true</InvariantGlobalization>
  3. Add following setting to Dockerfile's From base AS final stage(It's required to run .NET8 app on .NET9 runtime)
    ENV DOTNET_ROLL_FORWARD=LatestMajor
    
  4. Change base images to use mcr.microsoft.com/dotnet/sdk:9.0-alpine3.22-amd64
  5. Modify Program.cs with following code.
    public static void Main()
    {
        var data = new[] { "aaa", "BBB", "ccc" };
    
        var sorted = data.OrderBy(x => x, StringComparer.InvariantCulture);
    
        foreach (var s in sorted)
            Console.WriteLine(s);
    }
  6. Run application on docker container

Expected result

Sorted by Ordinal orders (It's enforced by InvariantGlobalization mode)

BBB
aaa
ccc

Actual result

Sorted by InvariantCulture orders

aaa
BBB
ccc

Other information

Alpine image for .NET SDK install ICU packages and disable InvariantMode explicitly.
https://github.com/dotnet/dotnet-docker/blob/main/src/sdk/9.0/alpine3.22/amd64/Dockerfile#L30

But when enable InvariantGlobalization setting on csproj.
It's output following settings on runtimeconfig.json.

And it has a higher priority than the environment variable. (I've also confirmed actual behavior on Windows environment)
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables?utm_source=chatgpt.com#set-invariant-mode

But it seems environment variable setting is used on Alpine image.
Because it works as expected when overwrite environment variable with following setting.

ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true


This issue is occurred only when using Alpine base image(.NET 9 SDK /.NET 10 SDK)
It's not happens when running on .NET 8 SDK image.

I've tested following images and it works as expected (InvariantMode is always used)

  • Ubuntu 24.04
  • Debian 12
  • Azure Linux 3.0

Output of docker version

Server: Docker Desktop 4.45.0 (203075)
 Engine:
  Version:          28.3.3
  API version:      1.51 (minimum version 1.24)
  Go version:       go1.24.5
  Git commit:       bea959c
  Built:            Fri Jul 25 11:34:00 2025

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions