Search code examples
c#signalrsignalr-backplane

SignalR Redis backplane not working - dependency issue?


We're using SignalR with the Redis (Azure cache) backplane in our redundant Azure web application. We detected a few days ago that all SignalR messages didn't seem to get delivered (it has worked in the past), thus pointing to problem with the backplane.

The application uses ASP.Net Owin startup as well as Autofac as IoC for the hubs, and we start up SignalR like this:

GlobalHost.DependencyResolver.UseRedis(new RedisScaleoutConfiguration(redisConnectionString, signalrRedisKey));
var hubConfiguration = new HubConfiguration
{
    Resolver = new AutofacDependencyResolver(resolver)
};
app.UseAutofacMiddleware(resolver);
app.MapSignalR("/signalr", hubConfiguration);

It doesn't matter if I change the Redis backplane configuration string to something invalid, it just won't connect. The SignalR code is located in another assemby than the web host.

I do not get any exceptions in the application iself, but I'm getting the follwing error when tracing SignalR:

SignalR.ReflectedHubDescriptorProvider Warning: 0 : Some of the classes from assembly "Microsoft.AspNet.SignalR.Owin, Version=1.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could Not be loaded when searching for Hubs. [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET

Files\root\79fa3057\a44a64e\assembly\dl3\75de3633\cfc73faf_eb21d101\Microsoft.AspNet.SignalR.Owin.dll]

Original exception type: ReflectionTypeLoadException Original exception message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Is it a dependency problem with nuget?

Here's an relevant excerpt from our packages.config:

<package id="Autofac" version="3.5.2" targetFramework="net46" />
<package id="Autofac.Owin" version="3.1.0" targetFramework="net46" />
<package id="Autofac.SignalR" version="3.0.2" targetFramework="net46" />
<package id="Castle.Core" version="3.3.3" targetFramework="net46" />
<package id="Microsoft.AspNet.SignalR.Client" version="2.2.0" targetFramework="net46" />
<package id="Microsoft.AspNet.SignalR.Core" version="2.2.0" targetFramework="net46" />
<package id="Microsoft.AspNet.SignalR.Redis" version="2.2.0" targetFramework="net46" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net46" />
<package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net46" />
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net46" />
<package id="Owin" version="1.0" targetFramework="net46" />
<package id="StackExchange.Redis.StrongName" version="1.0.488" targetFramework="net46" />

Really grateful for your help!


Solution

  • I found the problem :-) As we're using OWIN nothing should be registered through GlobalHost. Here is the working solution:

    var hubConfiguration = new HubConfiguration
    {
        Resolver = new AutofacDependencyResolver(resolver)
    };
    app.UseAutofacMiddleware(resolver);
    app.MapSignalR("/signalr", hubConfiguration);
    
    hubConfiguration.Resolver.UseRedis(new RedisScaleoutConfiguration(redisConnectionString, signalrRedisKey));