Skip to content

StringComparer.InvariantCulture.GetHashCode throws in Windows 7 compat mode #13352

@vitek-karas

Description

@vitek-karas

Repro

dotnet new console
Use this code in Main

            string value = @"Some";
            IEqualityComparer<string> comparer = StringComparer.InvariantCulture;
            Console.WriteLine($"{comparer.GetHashCode(value)}");

Build with .NET Core 3.0.
Go to the output folder and set compatibility mode for the .exe to Windows 7.
Run the exe.

Output

Unhandled exception. System.ArgumentException: External component has thrown an exception.
   at System.Globalization.CompareInfo.GetHashCodeOfStringCore(ReadOnlySpan`1 source, CompareOptions options)
   at System.Globalization.CompareInfo.GetHashCodeOfString(String source, CompareOptions options)
   at System.CultureAwareComparer.GetHashCode(String obj)
   at ConsoleApp3.Program.Main(String[] args)

This seems to happen for any string other than empty string. The program works fine when executed without the compatibility mode set.

I haven't tried to run this on actual Windows 7 machine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.GlobalizationenhancementProduct code improvement that does NOT require public API changes/additionsos-windowstracking-external-issueThe issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions