runtime: StringComparer.InvariantCulture.GetHashCode throws in Windows 7 compat mode

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.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 15 (15 by maintainers)

Commits related to this issue

Most upvoted comments

CC @ericstj

This will be risky to try to fix for 3.0. This is not a new issue and existed in previous releases too. We never supported running .net core apps under the Windows comparability modes. trying to fix that will not only just fixing this case but also we’ll need to do more work to ensure we run fine under the comparability modes.

Also, the underlying issue is really a bug in Windows and not in our products. I contacted Windows team before and they decided to not fix it. I’ll try to bring this issue back to them to consider. but for now, I am going to move this issue to 5.0 release and apps need to work around this by not applying the compatibility mode.

This is done!

Yes please let’s use issues + 3.0.x milestone for now while we figure out process.