Saturday, February 23, 2013

SignalR: Using a Hub instance not created by the HubPipeline is unsupported

When you need to push data to a SignalR hub from outside the hub (from a Controller for example), don't try to create a new instance of the Hub, like I did. Otherwise you'll see this nice exception:

"Using a Hub instance not created by the HubPipeline is unsupported"

From Microsoft.AspNet.SignalR.Core

Instead, the hub context must be retrieved:

var context = GlobalHost.ConnectionManager.GetHubContext<HubType>();
context.Clients.All.Whatever();

6 comments:

  1. Hello, The problem is that you can't target the Caller using this solution. Any help ?

    ReplyDelete
  2. http://www.asp.net/signalr/overview/signalr-1x/getting-started/introduction-to-signalr

    ReplyDelete
  3. Hello...
    I want to user Clients.Caller with HubContext but it's showing me error that I can not use Clients.Caller with Hub Context

    var context = GlobalHost.ConnectionManager.GetHubContext();
    context.Clients.Caller.receiver(respose); //I need to use like this but fail

    ReplyDelete

Note: Only a member of this blog may post a comment.