possible exceptions from IClientProxy.SendAsync (from Microsoft.AspNetCore.SignalR)

Viewed 627

In SignalR v2, I used code like this (below) to handle exceptions that happened when my connections failed. What is the equivalent in SignalR v3? Does SendAsync or SendAsyncCore throw some exception should connections fail or serialization fail?

private async void ManagerOnUserRemoved(UserDto userDto)
{
    try
    {
        await Context.Clients.All.MyFunc(userDto);
    }
    catch (InvalidOperationException) { }
    catch (AggregateException) { }
}

I didn't see any exceptions listed here: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.signalr.client.hubconnectionextensions.sendasync?view=aspnetcore-3.0

Update: I have the same question for the calls from the client-side (to InvokeCoreAsync et al).

2 Answers
private async void ManagerOnUserRemoved(UserDto userDto)
{
    try
    {
        await Context.Clients.All.MyFunc(userDto);
    }
    catch(Exception ex) { 
//Now check exceptions what you want by exception message or exception code
    }
}

With this code you can handle all exceptions, or you can do this:

 hubConnection.Error += ex => Console.WriteLine("Error: {0}", ex.Message);

I think it will be help

Related