SignalR problem: An unexpected error occurred invoking

osyris 236 Reputation points
2021-10-09T15:31:42.91+00:00

I simply try to invoke a message and i get an error:

Unhandled Rejection (Error): An unexpected error occurred invoking 'SendMessageToGroup' on the server.

C# Hub:

public class ChatHub : Hub
    {
        public async Task SendAll(string message)
        {

            await Clients.All.SendAsync("ReceiveAllMessage", message);
        }


        public async Task JoinGroup(string group)
        {
            await Groups.AddToGroupAsync(Context.ConnectionId, group);
        }

        public async Task SendMessageToGroup(string group, string message)
        {
            string time = DateTime.Now.ToString();
            await Clients.Groups(group).SendAsync("ReceiveMessage", message, time);
        }

        public override async Task OnConnectedAsync()
        {
            string userId = "user32";

            await Clients.Caller.SendAsync("UserConnected", userId);
            await base.OnConnectedAsync();
        }

    }

Client side: ReactJs:

const send = async () => {

    console.log("send to group")
   await Newconnection.invoke("SendMessageToGroup", cookies.Default, text)
   await Newconnection.invoke("SendAll","3r2r");

    const data = {
        "message" : text,
        "accesToken" : cookies.Default,
        "isHelper" : false
        }

          const res = await axios.post('https://localhost:44332/api/LiveChat/Message',data)
            if(res.status === 200)
            console.log("succesful send message")
}
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,080 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,222 questions
{count} votes