Why is my HubConnectionBuilder not working on HubConnectionBuilder().Build?

3

I am trying to learn how to connect to the SignalR Server using the C# client. And I am not sure if the steps I am performing would be considered ok (would work). As I am getting errors of course...

I am trying to establish a connection to the site as:

        var connection = new HubConnectionBuilder()
            .WithUrl(new Uri("http://localhost:5100/appsHub"))
            .WithAutomaticReconnect()
            .Build();

Once I run this I get the below. I am not quite sure what is the issue though here is it because of the link? Or should I use a different project by default?

Inner Exception 1:
FileLoadException: Could not load file or assembly 'System.Text.Encodings.Web, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)

And then I want to send the id to the URL As a JSON object.

I have been trying to get this working for a week and yes, I am not sure how to do it :(.

Any help would be appreciated.

Regards,

c#
json
http
signalr
asked on Stack Overflow Dec 16, 2020 by YoungDad

2 Answers

3

Be careful with tutorials. Usually they use latest package versions. E.g. ASP.NET Core SignalR .NET Client offers to do this:

Install-Package Microsoft.AspNetCore.SignalR.Client

This works fine if the latest package version targets the same framework version as your project does. But if your project targets another framework version, then you will get errors like you posted.

At the moment default target framework for console apps in VS2019 is netcoreapp3.1.
Latest Microsoft.AspNetCore.SignalR.Client requires net5.0.

Either change target framework to net5.0 for your console app, or use Microsoft.AspNetCore.SignalR.Client v3.1.x (3.1.10 is the latest compatible with netcoreapp3.1).


This package versioning is very annoying, IMO.

We have about 300 projects, and our LTS version will use netcoreapp3.1 till the end of its life. If one opens LTS version sources and Nuget tab inside VS now, he sees a lot of "available" package updates. But these updates cannot be applied because of incompatible framework versions. These garbage hides important updates for a number of third-party packages, which targets netstandard and don't belong to .NET Core/.NET.

As a result, a lot of wasted time to monitor updates for third-party packages.

answered on Stack Overflow Dec 16, 2020 by Dennis • edited Dec 16, 2020 by Dennis
1

Your problem is probably the version incompatibility of the project framework and the "* .SignalR.Client" package.

Right click on your project and check the target framework version from the properties menu. Versions must be compatible with the "* .SignalR.Client" package.

like here


User contributions licensed under CC BY-SA 3.0