Skip to content

StringComparer.CurrentCultureIgnoreCase.GetHashCode is broken (on Blazor) #70441

@tfenise

Description

@tfenise

Description

StringComparer.CurrentCultureIgnoreCase.GetHashCode is broken on Try .NET used by Microsoft Docs, which is powered by Blazor.

Reproduction Steps

Go to https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.-ctor?view=net-6.0#code-try-7. Run the code example in the online .NET Editor.

Expected behavior

It should produce the output as indicated at the end of the code example.

In particular,

Dictionary<string, string> openWith =
    new Dictionary<string, string>(
    StringComparer.CurrentCultureIgnoreCase);
openWith.Add("bmp", "paint.exe");
openWith.Add("BMP", "paint.exe");

should fail.

Actual behavior

The actual output is different from what is indicated at the end of the code example. In particular, openWith.Add("BMP", "paint.exe"); succeeds. Further investigation reveals that StringComparer.CurrentCultureIgnoreCase.Equals("bmp", "BMP") is indeed true, but StringComparer.CurrentCultureIgnoreCase.GetHashCode("bmp") and StringComparer.CurrentCultureIgnoreCase.GetHashCode("BMP") happen to be different.

Regression?

I don't know.

Known Workarounds

None.

Configuration

I am not familiar with Blazor, but System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription says Mono 6.5.0 (explicit/9f49cc85af1). I am using Microsoft Edge 102.0.1245.33 (64bit) on Windows 11 x64.

The (offline, non-Blazor) .net on my computer seems to have no problem with this code example.

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions