Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a .Net Framework SignalR client to connect to .Net Core SignalR Server?

This is basically a copy of this question but the repository has been archived so I can't ask it there: https://github.com/aspnet/SignalR/issues/1645

I am trying to get an older application running .NET Framework to connect to a newer application running .NET Core using SignalR. I've read some posts that say that the AspNetCore & AspNet versions of SignalR are incompatible, so the goal is to get a Microsoft.AspNetCore.SignalR.Client running on the .NET Framework application.

I've made a test project using framework version 4.6.1, which I believe is .NET Standard 2.0 so I should be able to install this package https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client/1.0.0-preview1-final according to a comment by davidfowl I'm unable to install this package on my 4.6.1 project so I must be doing something wrong.

I also tried another workaround which was creating a netstandard2.0 library using the Microsoft.AspNetCore.SignalR.Client v3.1.6 code, and then referencing the .dll from my 4.6.1 project.

The 3.1.6 code in my netstandard2.0 library looks like this:

using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Concurrent;
public class SignalRConnection
{       
    private readonly HubConnection hubConnection;

    public SignalRConnection(string endpoint)
    {
        this.endpoint = endpoint;
        hubConnection = new HubConnectionBuilder()
         .WithUrl(endpoint)
         .Build();
    }
}

I've referenced this by going to references in my 4.6.1 project, right clicking and pressing add reference and selecting my netstandard2.0 project. The 4.6.1 code that I am calling this with is:

class Program
{
   static void Main(string[] args)
   {
      SignalRConnection connection = new SignalRConnection("http://localhost:8080/status");
   }
}

I thought this might be because I'm not using 1.0.0, so I also tried with that version. I get the same exception FileNotFoundException but for each different version.

 System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.AspNetCore.SignalR.Client.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.'

Cannot load Microsoft.AspNetCore.SignalR.Client.Core

Has anyone had any luck connecting a .NET Framework app to a .NET Core app using SignalR and could give me some pointers on where I've went wrong? Thank you

Edit:

Nuget SignalR error

I was able to get this to install in a 4.6.1 project using VS 2019, but when I tried to install it into a 4.6.1 project in VS 2015 it gave me the above error

like image 507
craigbot Avatar asked Oct 02 '20 20:10

craigbot


People also ask

How do I use .NET core SignalR?

In Solution Explorer, right-click the project, and select Add > Client-Side Library. In the Add Client-Side Library dialog, for Provider select unpkg. For Library, enter @microsoft/signalr@latest . Select Choose specific files, expand the dist/browser folder, and select signalr.

What platform does SignalR client supports?

SignalR can be used in the following browsers: Microsoft Internet Explorer versions 11. Windows only. Microsoft Edge(Chromium).

Can I use SignalR with ASP NET Core?

So far, you've seen how to use ASP.NET Core with the JavaScript SignalR client library in the browser. SignalR also has a .NET Standard 2.0 client library that can be used to connect to a SignalR hub from applications built on .NET Core, .NET Framework, and more.

What is SignalR client in WPF?

The ASP.NET Core SignalR .NET client library lets you communicate with SignalR hubs from .NET apps. The code sample in this article is a WPF app that uses the ASP.NET Core SignalR .NET client. The Microsoft.AspNetCore.SignalR.Client package is required for .NET clients to connect to SignalR hubs.

What is SignalR client NuGet?

The Microsoft.AspNetCore.SignalR.Client NuGet package contains the .NET client libraries for ASP.NET Core SignalR. Use the HubConnectionBuilder to create and build an instance of a connection to a hub. ASP.NET SignalR supports SQL Server and Redis. ASP.NET Core SignalR supports Azure SignalR Service and Redis.

How do I install the SignalR client library?

Install the SignalR .NET client package The Microsoft.AspNetCore.SignalR.Clientpackage is required for .NET clients to connect to SignalR hubs. Visual Studio .NET Core CLI To install the client library, run the following command in the Package Manager Consolewindow:


Video Answer


1 Answers

Thanks to Camilo Terevinto for giving me the answer for this. If you are using VS 2019 then this is solved already (just use nuget and install)

But if you need to use VS 2015, then it is not working due to nuget being out of date.

Install the most up to date nuget.exe from https://www.nuget.org/downloads

Run .\nuget.exe install Microsoft.AspNetCore.SignalR.Client -OutputDirectory C:\Projects\SignalR\ConsoleApplication1\ConsoleApplication1\packages

Then manually update your .csproj/packages.config with the added packages (note I also needed netstandard added to my project for it to work) For my .csproj:

<ItemGroup>
    <Reference Include="netstandard" />
    <Reference Include="Microsoft.AspNetCore.SignalR.Client.Core, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
        <HintPath>..\packages\Microsoft.AspNetCore.SignalR.Client.Core.3.1.8\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Client.Core.dll</HintPath>
    </Reference>
...

There are a lot more references added when installing this package so just add them all (I'm not adding them all here since there are 20+)

Then do the same for your packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
    <package id="Microsoft.AspNetCore.Connections.Abstractions" version="3.1.8" targetFramework="net461" />
...

Once done I just restarted my project and was able to use the signalR client

like image 53
craigbot Avatar answered Oct 16 '22 16:10

craigbot