Skip to content

Behavior changes of AppContextConfigHelper on .NET 9 #121899

@filzrev

Description

@filzrev

Description

There is a following documentation.
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#set-invariant-mode

A value set in the project file or runtimeconfig.json has a higher priority than the environment variable.

When switch is defined at runtimeconfig.json level. it should not be overwritten by environment variable setting.
But when using .NET 9/.NET 10. This behavior seems be changed. (Environment variable has higher priority)

Reproduction Steps

  1. Create console application
  2. Modify csproj and add following settings
    <TargetFramework>net9.0</TargetFramework>
    <InvariantGlobalization>true</InvariantGlobalization>
  3. Modify Program.cs with following code
    static void Main(string[] args)
    {
        var data = new[] { "aaa", "BBB", "ccc" };
    
        var sorted = data.OrderBy(x => x, StringComparer.InvariantCulture);
    
        foreach (var s in sorted)
            Console.WriteLine(s);
    }
  4. Add Properties/launchSettings.json with following content
    {
      "profiles": {
        "Default": {
          "commandName": "Project",
          "commandLineArgs": "",
          "environmentVariables": {
            "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT": "false"
          }
        }
      }
    }
  5. Launch application with .NET 9

Expected behavior

It's expected Ordinal sorted results are shown (InvariantGlobalization is enabled)

BBB
aaa
ccc

Actual behavior

InvariantCulture sorted results are shown (InvariantGlobalization is disabled)

aaa
BBB
ccc

Regression?

When running application on .NET 8 (net80).
It works as expected.

So it's breaking changes or regression.

I've confirmed relating PR(#87672) and Breaking changes in .NET 9 but can't find related information.

I'm wondering if the changes in behavior are intentional or not.
If it's intentional changes, it need to fix documentation.

Known Workarounds

No response

Configuration

No response

Other information

It seems behavior changes are introduced at v9.0.0-preview.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-HostuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions