7

I have a a SignalR client which seems to close straight after starting, the error message i get is:

"The server closed the connection with the following error: Connection closed with an error. InvalidOperationException: Sequence contains no elements"

The SignalR client is being used in a ASP.Net Core Web API project (within an API controller).

The Nuget package i am using is called Microsoft.AspNetCore.SignalR.Client (v 1.1.0)

My code looks like this:

    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
    }
user1786107
  • 2,921
  • 5
  • 24
  • 35

1 Answers1

26

On your server you can turn on detailed errors via:

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

This will then give you a more detailed error message on the client

Tito
  • 663
  • 1
  • 8
  • 14