Bhavesh Ghul

Bhavesh Ghul

  • 822
  • 1k
  • 54.2k

I am using signalR Method - Clients.Caller.receiver(re)

Sep 21 2018 8:57 AM
I am using signalR for private message chat application and in that, I am calling
 

Clients.Caller.receiver(re)

response pass successfully but suddenly in catch, I get an error for "Using a Hub instance not created by the HubPipeline is unsupported". Now I can't understand that where reference is missing. Please help me solve this one.

I am using below code

  1. public async Task GetAllMessages(int roomid, int fromuserId, int touserId, int index, int pageSize, int broadcastid = 0)  
  2.             {  
  3.                 ResponseModel re = new ResponseModel();  
  4.                 try  
  5.                 {  
  6.                     var model = new MessageDetailModel  
  7.                     {  
  8.                         Index = index,  
  9.                         PageSize = pageSize,  
  10.                         FromUserId = fromuserId,  
  11.                         ToUserId = touserId,  
  12.                         ChatRoomId = roomid,  
  13.                         BroadCastId = broadcastid  
  14.                     };  
  15.                     MesaageModel totalmessages = new MesaageModel();  
  16.                     List<RecentMessage> messages = new List<RecentMessage>();  
  17.                     var usermessages = await _userService.GetAllMessages(model);  
  18.                     messages.AddRange(usermessages);  
  19.                     foreach (var message in messages)  
  20.                     {  
  21.                         model.BroadCastMessageId = model.BroadCastId == 0 ? 0 : message.BroadCastMessageId;  
  22.                         model.ChatRoomMessageId = model.BroadCastId == 0 ? message.ChatRoomMessageId : 0;  
  23.                         List<UserDetail> userofseenby = new List<UserDetail>();  
  24.                         var users = await _userService.GetMessageSeenBy(model);  
  25.                         userofseenby.AddRange(users);  
  26.                         message.SeenBy = userofseenby;  
  27.                     }  
  28.   
  29.                     totalmessages.Messages = messages;  
  30.   
  31.                     totalmessages.UnseenMessageCount = await _userService.GetUnSeenCount(messages.FirstOrDefault().ChatRoomId, fromuserId);  
  32.                     if (messages.FirstOrDefault().IsBroadCast == true)  
  33.                         totalmessages.Users = (List<UserDetail>)await _userService.GetUsersByBroadCastId(messages.FirstOrDefault().BroadCastId);  
  34.                     else if (messages.FirstOrDefault().IsGroup == true)  
  35.                         totalmessages.Users = (List<UserDetail>)await _userService.GetUsersByChatRoomId((int)messages.FirstOrDefault().ChatRoomId);  
  36.                     re.MsgCode = 0; re.MsgText = "Success"; re.MsgType = MessageType.Success;  
  37.                     re.ActionCommand = "onAllMessagesReceived";  
  38.                     re.SingleObject = totalmessages;  
  39.                     Clients.Caller.receiver(re);  
  40.                 }  
  41.                 catch (Exception ex)  
  42.                 {  
  43.                     re.ActionCommand = "onAllMessagesReceived";  
  44.                     re = ResponseHelper.ErrorResponse(re.ActionCommand, ex.ToString());  
  45.                     Clients.Caller.receiver(re);  
  46.                 }  
  47.             }  

 

Answers (3)