Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SignalR Core on .NET 4.6.1

As said in the SignalR differences documentation we can use SignalR Core on .NET 4.6.1 and latter...

SignalR differences

So I know the code for the startup and configuration for both cases:

SignalR Core:

ConfigureServices

//Add SignalR service
services.AddSignalR();

Startup

app.UseSignalR(routes =>
{
    routes.MapHub<NotificationsHub>("/notification");
});

SignalR:

Startup

app.Map("/signalr", map =>
{
    map.UseCors(CorsOptions.AllowAll);
    var hubConfiguration = new HubConfiguration { };
    hubConfiguration.EnableDetailedErrors = true;
    map.RunSignalR(hubConfiguration);
});

And my question is, what I need to do in the .NET 4.6.1 startup to map my SignalR hub and etc...? I can't find any documentation about this particular case.

Update1: I tried to run the same code and obviously changed the client code to use the SignalR core approach and what I get now is (not authorized) during negotiation request.

like image 741
Kiril1512 Avatar asked Oct 07 '19 12:10

Kiril1512


2 Answers

After some research and after I asked this same question on the ASP.NET forum, I came to the result of that it is not possible to use SignalR Core on any .NET Framework project. We can use it only on .NET Core projects and it supports targeting framework to .NET Framework 4.6.1 or later then compile and run the application on supported platform.

More details here: https://forums.asp.net/t/2160460.aspx

like image 97
Kiril1512 Avatar answered Nov 12 '22 04:11

Kiril1512


While this question was already answered by the OP I think a more complete answer is warranted for the benefit of others who may stumble across it.

ASP.NET Core versions 1 through 2.2 supported targetting .NET Framework v4.6.1+ to ease transitioning from ASP.NET v4 to ASP.NET Core. This support was dropped in ASP.NET Core v3.

While both SignalR and SignalR Core have nuget packages targetting .NET Framework v4.6.1+ they have different dependencies. This is made slightly more confusing due to one of the SignalR nuget packages being called Microsoft.AspNet.SignalR.Core.

The long and short of it is SignalR Core was built upon ASP.NET Core. You cannot use SignalR Core without it. If you want to use SignalR Core while still targetting .NET Framework v4.6.1-v4.8 you can do so only by creating a ASP.NET Core v1-v2.2 project then changing it's target framework to .v4.6.1-v4.8.

For ASP.NET v4 applications as of this writing the latest supported version of SignalR is v2.4.3.

like image 2
Kenneth Cochran Avatar answered Nov 12 '22 03:11

Kenneth Cochran