Using SignalR 2 in ASP.NET 5 application

SignalR 3 and ASP.NET 5 were working together nicely up until the beta7 version. Now Microsoft states that SignalR 3 is ‘on hold’, and one should not expect the two to work together in the near future:

https://github.com/aspnet/SignalR-Server/issues/119

https://github.com/aspnet/SignalR-Server/issues/121

So the question: is there a way to make at least SignalR 2 work in an ASP.NET 5 app?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Found the general solution for using owin-compatible middleware in this article:
https://lbadri.wordpress.com/2014/11/01/asp-net-vnext-middleware-versus-owinkatana-middleware/

  1. Reference the Microsoft.AspNet.Owin package
  2. Insert the following code into Startup.Configure:
app.UseOwin(addToPipeline =>
{
    addToPipeline(next =>
    {
        var appBuilder = new AppBuilder();
        appBuilder.Properties["builder.DefaultApp"] = next;

        appBuilder.MapSignalR();

        return appBuilder.Build<AppFunc>();
    });
});

Method 2

SignalR 2 also runs on .NET Core 2, when you poke around in the internals:

// SignalR checks if it's running in a Mono environment and then
// disables features like performance counters
// .NET Core isn't Mono, but doesn't have the performance counters DLL
// Let's make .NET Core a Mono
var signalRAssembly = typeof(Microsoft.AspNet.SignalR.PersistentConnection).Assembly;
// This type is internal
var monoUtility = signalRAssembly.GetType("Microsoft.AspNet.SignalR.Infrastructure.MonoUtility");
var field = monoUtility.GetField(
    "_isRunningMono",
    BindingFlags.NonPublic | BindingFlags.Static
);
field.SetValue(null, new System.Lazy<bool>(() => true));


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x