Skip to content

Should Environment.GetEnvironmentVariables return case-insensitive collection on Windows? #124378

@adamsitnik

Description

@adamsitnik

As pointed by @stephentoub in #124271 (comment):

var d = Environment.GetEnvironmentVariables();
d.Clear();
d.Add("s", 123);
d.Add("S", 456);
foreach (var v in d)
{
    Console.WriteLine(v);
}

prints

[S, 456]
[s, 123]

rather than

[S, 456]

I personally don't have a strong opinion on this, the API just returns a snapshot. However, if we decide to change it, we could eliminate some extra copying when creating env var dictionary for process:

_environmentVariables = new DictionaryWrapper(new Dictionary<string, string?>(
envVars.Count,
OperatingSystem.IsWindows() ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal));

cc @GrabYourPitchforks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions