SignalR-客户端连接在启动后立即关闭-InvalidOperationException:序列不包含任何元素

问题描述 投票:0回答:1

我有一个SignalR客户端,它似乎在启动后立即关闭,我收到的错误消息是:

“服务器关闭连接并出现以下错误:连接关闭并发生错误。InvalidOperationException:序列不包含任何元素”

SignalR客户端正在ASP.Net Core Web API项目(在API控制器内)中使用。

我正在使用的Nuget包称为Microsoft.AspNetCore.SignalR.Client(v 1.1.0)

我的代码如下:

    try
    {
        //SEND MESSAGE TO HUB
        var connection = new HubConnectionBuilder()
            .WithUrl("https://sample.azurewebsites.net/ChatHub")
            .Build();

        connection.Closed += async (error) =>
        {
            //log error - this is getting called straight after StartAsync
        };

        await connection.StartAsync();

        await connection.InvokeAsync("SendToATeam", "x", "y");

        await connection.StopAsync();            
    }
    catch (Exception ex)
    {
        //log error
    }
c# .net signalr signalr.client asp.net-core-signalr
1个回答
0
投票

在您的服务器上,您可以通过以下方式打开详细的错误:

services.AddSignalR(o =>
{
  o.EnableDetailedErrors = true;
})

这将在客户端上为您提供更详细的错误消息

© www.soinside.com 2019 - 2024. All rights reserved.