Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR ASPNetHost does not exist in the current context

Tags:

c#

mono

signalr

I've downloaded the latest SignalR code (as of 04/04/12) from GitHub as it now compiles with MonoDevelop so I can use it on OS X.

But while testing the new version with the SignalR.Sample example listed on the Getting Started page, it fails with the following error:

The name 'AspNetHost' does not exist in the current context

This occurs in StockTicker.cs here:

private static dynamic GetClients()
{
    return AspNetHost.DependencyResolver.Resolve<IConnectionManager>().GetClients<StockTickerHub>();
}

Can anyone explain what has become of AspNetHost?

Suggestions on how to get the SignalR.Sample compiling would be very welcome.

like image 480
Mattl Avatar asked Apr 04 '12 16:04

Mattl


1 Answers

I had the same problem and found that this was deprecated in SignalR 0.5. Here is an article detailing the changes.

Specific to your item, the change is from this:

public void PerformLongRunningHubOperation()
{
    var clients = AspNetHost.DependencyResolver.Resolve<IConnectionManager>().GetClients<MyHub>();

    clients.notify("Hello world");
}

To this in 0.5:

public void PerformLongRunningHubOperation()
{
    IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();

    context.Clients.notify("Hello world");
}
like image 139
Gene Reddick Avatar answered Oct 09 '22 11:10

Gene Reddick