Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Core SignalR cannot add or use in startup

Ive recently come back to an old .Net Core application which was using SignalR.

I think at the time the only SignalR NuGet package available for .Net Core applications was a preview. And it worked.

Im now on a new machine and dont know what the preview feed was for this package so ive uninstalled it and installed this:

> Install-Package Microsoft.AspNet.SignalR.Core -Version 2.4.1

Everything seems fine with a few namespace changes apart from these two errors in the Startup.cs file.

Error CS1061 'IServiceCollection' does not contain a definition for 'AddSignalR' and no accessible extension method 'AddSignalR' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

Error CS1061 'IApplicationBuilder' does not contain a definition for 'UseSignalR' and no accessible extension method 'UseSignalR' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

I've looked around and there isn't much available for me, other than someone suggesting you need to install Microsoft.AspNetCore.SignalR.Http which I cant find. Someone else suggested you need to install this:

Install-Package Microsoft.AspNetCore.SignalR.Client -Version 1.1.0

Which I've tried, but the errors remain, how do I get these to go away?

enter image description here

like image 900
JsonStatham Avatar asked Aug 21 '19 11:08

JsonStatham


People also ask

Is SignalR deprecated?

SignalR is deprecated. May I know the latest package for the same. - Microsoft Q&A.

Do people still use SignalR?

SignalR is relevant for now, it supports mobile devices, and many other things. SignalR is the same WebSocket but with many ready stuff. You can use raw WebSocket instead of it, but you will have to do many things to gain what you want. So SignalR is more easy to use.

Is SignalR an RPC?

SignalR provides an API for creating server-to-client remote procedure calls (RPC). The RPCs invoke functions on clients from server-side .


1 Answers

I solved the issue by replacing the code from

app.UseSignalR(routes =>
        {
            routes.MapHub<NotifyHub>("notify"); 
        });

to

app.UseEndpoints(endpoints =>
        {
            endpoints.MapHub<NotifyHub>("/notify");
        });

I am using Dot net 5.0

like image 64
Farman Ameer Avatar answered Oct 10 '22 20:10

Farman Ameer