runtime: [8.0] HybridGlobalization problem in Blazor WASM targeting .NET 8 and published with .NET 9 SDK

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a Blazor WASM project that targeted .NET 8. After I installed the VS 2022 17.12 update, my app stopped working when published to a production server. The stack trace reported in the browser’s Console window was:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: TypeInitialization_Type, Menees.Chords.ChordProDirectiveLine
System.TypeInitializationException: TypeInitialization_Type, Menees.Chords.ChordProDirectiveLine
 ---> System.TypeInitializationException: TypeInitialization_Type, Menees.Chords.Parsers.ChordParser
 ---> System.PlatformNotSupportedException: PlatformNotSupported_HybridGlobalization, HashCode
   at System.Globalization.CompareInfo.GetHashCodeOfStringCore(ReadOnlySpan`1 , CompareOptions )
   at System.Globalization.CompareInfo.GetHashCode(ReadOnlySpan`1 , CompareOptions )
   at System.Globalization.CompareInfo.GetHashCode(String , CompareOptions )
   at System.CultureAwareComparer.GetHashCode(String )
   at System.Collections.Generic.HashSet`1[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].AddIfNotPresent(String , Int32& )
   at System.Collections.Generic.HashSet`1[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Add(String )
   at Menees.Chords.Parsers.ChordParser..cctor()
   Exception_EndOfInnerExceptionStack
   at Menees.Chords.ChordProDirectiveLine..cctor()
   Exception_EndOfInnerExceptionStack
   at Menees.Chords.Parsers.DocumentParser.ParseLines(TextReader reader)
   at Menees.Chords.Parsers.DocumentParser.Parse(TextReader reader)
   at Menees.Chords.Document.Parse(String text, DocumentParser parser)
   at Menees.Chords.Web.Index.ConvertInput()
   at Menees.Chords.Web.Index.OnInitializedAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

Others have reported similar problems on StackOverflow here.

The VS 17.12 update removed the .NET 8.0.404 SDK and replaced it with the .NET 9.0.100 SDK. Something isn’t working right with HybridGlobalization in that scenario.

I first worked around the problem by creating a global.json file and manually installing the .NET 8.0.404 SDK again (as suggested by Dimitris Maragkos). That commit can be seen here.

Later I worked around the problem by upgrading the project to target .NET 9 and publish with the .NET 9.0.100 SDK. That commit can be seen here.

The production problem only occurs when trying to target .NET 8 and publish with the .NET 9.0.100 SDK. That combination works in VS at build and debug time. It only fails when published. And my app does NOT opt-in with <HybridGlobalization>true</HybridGlobalization> as discussed here. I’m just using StringComparer.CurrentCultureIgnoreCase from a static initializer here.

Expected Behavior

A Blazor WASM app that targets .NET 8 should be publilshable using the .NET 9 SDK without throwing PlatformNotSupportedException: PlatformNotSupported_HybridGlobalization, HashCode at runtime.

Steps To Reproduce

No response

Exceptions (if any)

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: TypeInitialization_Type, Menees.Chords.ChordProDirectiveLine
System.TypeInitializationException: TypeInitialization_Type, Menees.Chords.ChordProDirectiveLine
 ---> System.TypeInitializationException: TypeInitialization_Type, Menees.Chords.Parsers.ChordParser
 ---> System.PlatformNotSupportedException: PlatformNotSupported_HybridGlobalization, HashCode
   at System.Globalization.CompareInfo.GetHashCodeOfStringCore(ReadOnlySpan`1 , CompareOptions )
   at System.Globalization.CompareInfo.GetHashCode(ReadOnlySpan`1 , CompareOptions )
   at System.Globalization.CompareInfo.GetHashCode(String , CompareOptions )
   at System.CultureAwareComparer.GetHashCode(String )
   at System.Collections.Generic.HashSet`1[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].AddIfNotPresent(String , Int32& )
   at System.Collections.Generic.HashSet`1[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Add(String )
   at Menees.Chords.Parsers.ChordParser..cctor()
   Exception_EndOfInnerExceptionStack
   at Menees.Chords.ChordProDirectiveLine..cctor()
   Exception_EndOfInnerExceptionStack
   at Menees.Chords.Parsers.DocumentParser.ParseLines(TextReader reader)
   at Menees.Chords.Parsers.DocumentParser.Parse(TextReader reader)
   at Menees.Chords.Document.Parse(String text, DocumentParser parser)
   at Menees.Chords.Web.Index.ConvertInput()
   at Menees.Chords.Web.Index.OnInitializedAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

.NET Version

9.0.100

Anything else?

This started after installing the VS 2022 17.12 update, which removed the .NET 8.0.404 SDK. I had to manually reinstall that SDK to continue to target and publish .NET 8 versions that worked.

dotnet --info
.NET SDK:
 Version:           9.0.100
 Commit:            59db016f11
 Workload version:  9.0.100-manifests.c6f19616
 MSBuild version:   17.12.7+5b8665660

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100\

.NET workloads installed:
 [wasm-tools-net6]
   Installation Source: VS 17.12.35506.116
   Manifest Version:    9.0.0/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.net6\9.0.0\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools]
   Installation Source: VS 17.12.35506.116
   Manifest Version:    9.0.0/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.current\9.0.0\WorkloadManifest.json
   Install Type:              Msi

 [aspire]
   Installation Source: VS 17.12.35506.116
   Manifest Version:    8.2.2/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
   Install Type:              Msi

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0
  Architecture: x64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  8.0.404 [C:\Program Files\dotnet\sdk]
  9.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  C:\Dev\Repos\Chords\global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 22 (10 by maintainers)

Most upvoted comments

Let me list a more detailed chain of events that made this issue surface only now.

Thank you for confirmation. Let’s mark it fixed with https://github.com/dotnet/runtime/pull/110183.

many thanks @ilonatommy.

I can confirm upgrading to VS17.12.4 and re-publishing no longer results in this error (for a .Net 8 app)

Got exactly same problem with a Blazor wasm application that is targeting .NET 8

Hi, i think you are correct. At the moment we have some problems in applying the workaround: for currently unknown reasons we are experimenting issues in publishing the project using the Visual Studio IDE, i think we experimented too much with some settings, in a desperate attempt to solve the original problem…

Thank you very much to have dig deeper in our issue, we have much appreciated it.

Hi, we have tried to publish our app disabling trimming from Blazor webassembly client project, unfortunatly with no success. In our case, the problem arises on rendering a chart component, which relies on HybridGlobalization (ScottPlot.NET). Hope bug fix will be released soon.

Thank you!

Sorry for the delay, I was away. I am looking into it, from some reason net8 trims the GetHashCodeOfStringCore method to

    private int GetHashCodeOfStringCore([In] ReadOnlySpan<char> obj0, [In] CompareOptions obj1)
    {
      if (true);
      throw new PlatformNotSupportedException(CompareInfo.GetPNSEText("HashCode"));
    }

where true is https://github.com/dotnet/runtime/blob/1e6311a9795556149b5a051c5f5b2159d5a9765c/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs#L19.

When we disable trimming (not recommended), the published app works fine. I will try to find out about the details behind it as soon as I can.