31

My .NET SignalR client code not working any more in Core 3 (WPF):

string hubAddress = "https://localhost:44329/Hub";
HubConnection hub = new HubConnectionBuilder().WithUrl(hubAddress).Build(); // WithUrl not found

MS document said it is there

Anyone know how to fix this?

David Tsui
  • 433
  • 1
  • 5
  • 8
  • 1
    `WithUrl()` is an extension method. Do you have `using Microsoft.AspNetCore.SignalR.Client;` in your C# file? – Dai Nov 03 '19 at 03:27
  • 1
    When I ran the package import from the quick fix menu it got the wrong one (in VS2019). I think it was the "AspNet.SignalR.Client". I had to remove that one and get the correct "AspNetCore…". – Brannon Apr 08 '20 at 14:28

2 Answers2

67

Found a solution: make sure project referencing Microsoft.AspNetCore.SignalR.Client, but not Microsoft.AspNetCore.SignalR.Client.Core.

Serzas
  • 1,016
  • 8
  • 8
  • 1
    This fixed my issue. It's hilarious that Microsoft makes the libraries so inconsistent. – fangzhzh Sep 20 '21 at 02:55
  • Microsoft.AspNetCore.SignalR.Client.Core depends on Microsoft.AspNetCore.SignalR.Client so you have to have both installed in the project. – Leszek Jezierski Aug 05 '22 at 19:33
  • 1
    @LeszekJezierski It's the other way round - The Client depends on Core. So you just have to reference Client and Core will be brought in. Client has the .WithUrl required. – Daniel Abbatt Sep 20 '22 at 20:59
13

Remove the dependency Microsoft.AspNetCore.SignalR.Client.Core from your app and then add

Using Package Manager Console

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

Using .Net CLI

dotnet add package Microsoft.AspNetCore.SignalR.Client --version 6.0.0

It will fix your issue

Aftab Ahmed
  • 665
  • 9
  • 17