SignalR Requests Throwing "Hub cannot be resolved."

I have been using SignalR from an earlier version and am updating along the way, however, I deployed my application on my working Windows Server 2008 R2 server, and now the application crashes with "The hub cannot be resolved." an exception.

edit: StackTrace Added:

[InvalidOperationException: 'stockitems' Hub could not be resolved.] Microsoft.AspNet.SignalR.Hubs.HubManagerExtensions.EnsureHub(IHubManager hubManager, String hubName, IPerformanceCounter[] counters) +426 Microsoft.AspNet.SignalR.Hubs.HubDispatcher.Initialize(IDependencyResolver resolver, HostContext context) +716 Microsoft.AspNet.SignalR.Owin.CallHandler.Invoke(IDictionary`2 environment) +1075 Microsoft.AspNet.SignalR.Owin.Handlers.HubDispatcherHandler.Invoke(IDictionary`2 environment) +363 Microsoft.Owin.Host.SystemWeb.OwinCallContext.Execute() +68 Microsoft.Owin.Host.SystemWeb.OwinHttpHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object extraData) +414 [TargetInvocationException: Exception has been thrown by the target of an invocation.] Microsoft.Owin.Host.SystemWeb.CallContextAsyncResult.End(IAsyncResult result) +146 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288 

On my dev machine and local test server I have no problem.

The node in question is really simple:

  [HubName("StockItems")] public class StockItemHub : Hub { } 

I initially thought this was a problem with HubName, so I deleted it, but it still explodes.

I initially thought this was due to dependency injection, so I changed my Global.asax to look like this:

  var signalRResolver = new SignalRDependencyResolver(); GlobalHost.DependencyResolver = signalRResolver; var configuration = new HubConfiguration { Resolver = signalRResolver }; RouteTable.Routes.MapHubs(configuration); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters, config.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); 

edit: what is SignalRDependencyResolver? SignalRDependencyResolver did not exist until I tried to solve this problem. Since I believe this is a dependency nesting problem, I wrapped DefaultDependencyResolver by overriding GetService and GetServices to check my Ninject kernel for this type first, and if not returning to DefaultDependencyResolver

Any ideas?

The server runs IIS7, Windows Server 2008 with .Net 4.5 The application is an MVC 4.Net 4.5

+4
source share
4 answers

Now this is an old question, but this weekend he raised his ugly head. After spending a lot of time investigating, I found that SignalR was not the only thing that broke down in the deployment, my WebAPI was also tossing around and could not find exceptions for the controller.

It turns out that this is caused by internal SignalR and WebApi signals that reflect all types in the Sites assembly. The TypeLoadException was an exception in my case because RoleEntryPoint was created for the class, which is a type of Azure, but as the site was deployed in an environment without azure light, things fell apart. Just eliminating this type from assemblies without Azure, the problem was resolved.

It would be nice if these TypeLoadExceptions were more visible, but they are.

+3
source

I had the same error due to the fact that my Hub class was internal , so SignalR could not find it in my assembly.

Setting the hub to public solved the problem.

+10
source

I am suffering from this problem just now, and I dig a little deeper, and just found a possible solution. My hub class is not in the web project assembly, they are in some reference assemblies. This is a very common scenario in a tiered application.

When starting, signalR will try to find the hub class with an instance of IAssemblyLocator. When deployed to the IIS website, this instance of IAssemblyLocator finds all referenced assemblies. But at the moment, the application is only at launch time, which means that many (referenced, but not yet downloaded) assemblies may NOT have been compiled by the owin hosting environment. Thus, the search for hub classes fails.

So, just add your assembly to the system.web / compilation / assembly section of Web.Config:

 <system.web> <compilation targetFramework="4.5"> <assemblies> <add assembly="HubAssembly, Version=1.0.0.0, Culture=neutral"/> </assemblies> </compilation> </system.web> 

Or, if you want, you can also solve this problem by running your own class IAssemblyLocator, registering it in the dependency resolver as soon as app.MapSignalR is called.

 using Microsoft.AspNet.SignalR.Hubs; public class AssemblyLocator : IAssemblyLocator { public IList<System.Reflection.Assembly> GetAssemblies() { // list your hubclass assemblies here return new List<System.Reflection.Assembly>(new []{typeof(HubAssembly.HubClass).Assembly}); } } // add following code to OwinStartup class Configuration method app.MapSignalR(); GlobalHost.DependencyResolver.Register(typeof(Microsoft.AspNet.SignalR.Hubs.IAssemblyLocator), () => new AssemblyLocator()); 
+3
source

Like @Jijie Chen, when I got into this problem, I found that he could not load my assembly containing my hub. However, the fix for me was simpler. In my case, I had three projects. All the logic, including the hub, was in my own project, and I had two projects designed to host owin. One of them was a console project that worked fine. Then I adapted this to a Windows service to host it. Well, for some reason I managed to forget to include a link to the project containing my hub. This still compiled fine, because the host code depends on the signalr / owin mapping functions that load the hub at runtime rather than compilation time. Therefore, when I started the service and try to connect, I received the hub without the specific error described here, because it could not find the assembly with my center.

+1
source

All Articles