SignalR 猝死 - 500 Internal Server Error

Sudden Death of SignalR - 500 Internal Server Error

我一直在绞尽脑汁想弄清楚发生了什么,我的 SignalR 服务器似乎工作正常,我可以使用 JQuery 连接到集线器,如下所示

 $.connection.hub.url = "https://mysite.azure/signalr/hubs/";        
        $.connection.hub.logging = true;
        var hub = $.connection.airP2P;
        var token = "abcd";
        $.connection.hub.qs = { 'access_token': token };
        console.log("Connecting.....");
        $.connection.hub.start({ jsonp: isChrome })
            .done(function () {
                console.log("Connected to Hub!");                
            })
            .fail(function () { 
                console.log("Could not Connect to signal R hub!"); });

但不是我的 Android 应用程序,它突然停止工作并给我 500 内部服务器错误如下

StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, 
Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent, 
Headers:
{
  Cache-Control: private
  Transfer-Encoding: chunked
  Server: Microsoft-IIS/10.0
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Set-Cookie: ARRAffinity=9865c22a2d9f2f551f361f12a9fa85ff22f916bd5bee09cf0caa99ac24419d10;Path=/;HttpOnly;Domain=mysite.azure
  Date: Wed, 05 Aug 2020 06:55:09 GMT
  Content-Type: text/html; charset=utf-8
}

我的代码如下

var querystringData = new Dictionary<string, string>
{
   { "access_token", User_Auth_Token }
};

hubConnection = new HubConnection("https://mysite.azure/signalr", querystringData);
mhubProxy = hubConnection.CreateHubProxy("myHubName");
await hubConnection.Start();

完全相同的代码工作正常,只是突然停止工作,知道吗?

根据@CodeCaster,查看服务器日志我发现了这个错误

System.ArgumentNullException: Value cannot be null. Parameter name: key at System.Collections.Generic.Dictionary2.FindEntry(TKey key)
at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.AuthorizeRequest(IRequest request)
at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(IDictionary2 environment) at Microsoft.Owin.Mapping.MapMiddleware.d__0.MoveNext()

当您 运行 Xamarin 应用 Linker 如以下问题

所述时,就会发生这种情况

after archive xamarin android signalr not work

为了解决这个问题,我必须在构建设置中禁用链接器。我仍然不确定如何正确解决此问题,因为禁用链接器会大大增加 APK 大小

可以在此处找到更多信息https://docs.microsoft.com/en-sg/xamarin/android/deploy-test/linker