question

osyris-3187 avatar image
0 Votes"
osyris-3187 asked LanHuang-MSFT commented

SignalR problem: An unexpected error occurred invoking

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")
 }






dotnet-aspnet-core-generaldotnet-aspnet-generaldotnet-aspnet-core-webapi
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @osyris-3187,
What type of project is your project, asp.net core or asp.net?
Maybe you can provide more detailed error information to help you.
Best regards,
Lan Huang

0 Votes 0 ·

0 Answers