'Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol' threw an exception

I am getting the following exception when running Xamarin Forms iOS app after upgrade to the latest Visual Studio Mac:

{System.TypeInitializationException: The type initializer for 'Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol' threw an exception. ---> System.MissingMethodException: Method not found: int System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeU…}

Code:

        string token = s.AccessToken().Result;

        _connection = new HubConnectionBuilder()
          .WithUrl(serverUrl, options =>
          {
              options.AccessTokenProvider = () => Task.FromResult(token);
              options.Transports = Microsoft.AspNetCore.Http.Connections.HttpTransportType.LongPolling;

          })
          //.WithAutomaticReconnect()
          //.ConfigureLogging(logging =>
          //{
          //    logging.AddDebug();
          //    logging.SetMinimumLevel(LogLevel.Debug);
          //
          //})
          .Build();

I've tried adding various NuGet packages including System.Text.Json (5.0.1) but doesn't seem to be working. Any body else facing this and any suggestions how to fix? Android app is working OK.

xamarin forms - 5.0.0.2012

Xamarin.iOS Version: 14.14.2.5

Xamarin.Android Version: 11.2.0.0

Visual Studio Mac 8.9 (build 1651)



Solution 1:[1]

I had the same problem and the only thing that worked for me is to install System.Memory 4.5.0 (on IOS) that specific version any other version doesn't work for some reason.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Orestis