Aspnetcore: SignalR .NetCore 3.0-- HubConnectionBuilder' does not contain a definition for 'WithUrl'

Created on 29 Apr 2019  路  6Comments  路  Source: dotnet/aspnetcore

Describe the bug

A clear and concise description of what the bug is.
Hi,
I'm trying to create a HubConnection on a Console App, but getting an error with .WithUrl.

Receiving the following error:

HubConnectionBuilder' does not contain a definition for 'WithUrl' and no accessible extension method 'WithUrl' accepting a first argument of type 'HubConnectionBuilder' could be found

My code:

using Microsoft.AspNetCore.SignalR.Client;

    class Program

    {

        public static async Task Main(string[] args)

        {

            var connection =  new HubConnectionBuilder()

           .WithUrl("https://localhost:44386/NotificationHub")

           .Build();

            await connection.StartAsync();
            while (true)
            {
                try
                {
                    await connection.StartAsync();

                    break;
                }
                catch
                {
                    await Task.Delay(1000);
                }
            }

            Console.WriteLine("Client One listening. Hit Ctrl-C to quit.");
            Console.ReadLine();
        }
    }
}
area-signalr

Most helpful comment

What does your .csproj look like?

I'm guessing you referenced Microsoft.AspNetCore.SignalR.Client.Core instead of Microsoft.AspNetCore.SignalR.Client in your .csproj. Change the reference and you'll see the WithUrl method.

All 6 comments

What does your .csproj look like?

I'm guessing you referenced Microsoft.AspNetCore.SignalR.Client.Core instead of Microsoft.AspNetCore.SignalR.Client in your .csproj. Change the reference and you'll see the WithUrl method.

Yeah, looks like that was the issue. Just a comment, I followed a prompt from VS19 suggesting I install that Microsoft.AspNetCore.SignalR.Client.Core.

Thanks for the help!

Was this prompt a ctrl-. on HubConnectionBuilder in the editor?

Yeah,

Unfortunately the HubConnectionBuilder type is in that package (Client.Core), but the WithUrl extension method is in Client. There isn't really a way to tell VS to suggest a different package (though that could be an interesting idea for the future).

Ctrl-. on the WithUrl method itself might have offered the right package.

Out of curiocity, did you look at a doc or tutorial before starting? Most of our docs should be referring to the correct package, but if you followed a different reference (or even if you followed one of our docs and missed the package ID) that's useful information for us in helping others avoid confusion :)

I got confused by which version I needed to install. Not sure if that would catch anyone else
http://assets.gocreative1.net/wp-content/uploads/sites/38/2019/11/signalrVersionConfused.jpg

Was this page helpful?
0 / 5 - 0 ratings