Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 461
Steve Avatar asked Dec 13 '22 07:12

Steve


1 Answers

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.

like image 70
Orestis Avatar answered Jun 10 '23 02:06

Orestis