Search code examples
c#.netunicode.net-6.0.net-4.8

Why does "ß".Equals("SS", StringComparison.CurrentCultureIgnoreCase) differ between Net 4.8 and 6.0?


The following code behaves differently between .NET 4.8 and .NET 6.0 with 4.8 behaving as I'd expect (see also Why is "ss" equal to the German sharp-s character 'ß'?)

Thread.CurrentThread.CurrentCulture = new CultureInfo("de-de");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-de");
var eq = "ß".Equals("SS", StringComparison.CurrentCultureIgnoreCase); 
// True in .NET 4.8 
// False in .NET 6.0

Solution

  • It's because they started using ICU in .NET 5 and later:

    This resulted in some behavioral differences in a handful of globalization APIs when running applications on different platforms

    There is more information about the differences here.

    You can prove that this is what caused the change by reverting to the old NLS library by adding the following to your project file:

    <ItemGroup>
      <RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
    </ItemGroup>
    

    After adding that and recompiling, the comparison will return true for .NET 5 or later instead of false.