What would cause @microsoft/signalr disconnection when returning a null response from an invoke method call?

Viewed 116

While using AspNetCore Hub (3.1.0.0), I have a method that returns an object. In some situations, I want to return null. This seems valid.

When the client performs an invoke and a valid string is returned, it works as expected. However, if the method returns null, the connection is disconnected with a generic error "Error: Invocation canceled due to the underlying connection being closed."

I first saw this on methods that return Entity Framework objects but I am seeing it on methods that return String as well.

On server (abbreviated):

public class MyHub : Hub
{
    public String TestString()
    {
        return "Hello";
    }

    public String TestNull()
    {
        return null;
    }
}

On client:

let myConnection = new signalR.HubConnectionBuilder()
                    .withUrl("MyHub")
                    .withAutomaticReconnect()
                    .build();

myConnection.start();  

myConnection.invoke('TestString').then( x => console.log(x) );   // works fine.

myConnection.invoke('TestNull').then( x => console.log(x) );     // disconnects.

I could understand if the error was something about not being able to parse the null response or something. But the connection dying with "Error: Invocation canceled due to the underlying connection being closed." does not seem right.

Any ideas?

I know I can catch the exception and that the withAutomaticReconnect correctly reconnects.. but a null return seems valid and I'd like to get it working that way.

Thanks.

0 Answers
Related