7
votes

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

1
You should be fine just by adding a reference to nuget.org/packages/Microsoft.AspNetCore.SignalR.Client/3.1.8 in the .NET 4.6.1 project. If that fails, post the exact error message. Notice that you may need to go to .NET 4.7.2 (.NET 4.6.1 isn't even supported anymore, there's no reason to use that)Camilo Terevinto
.NET 4.6.1 is not really .NET Standard. You should use .NET Framework 4.7.2 or 4.8 really.Dai
@CamiloTerevinto thanks for the response. I was able to install this package into 4.6.1 project in VS 2019, but still when I create a 4.6.1 project in VS 2015 I am unable to install this package (I've edited my question to show the error)craigbot
@craigbot Look at your MSBuild output log. I'm willing to bet that the NuGet package for Microsoft.AspNetCore.SignalR.Client does not include an assembly for your project. There's a major design flaw in NuGet right now where it won't block you (or even warn you!) when you install a package that doesn't add any assembly-reference dependencies to the target project.Dai
@Dai Sorry for not understanding, do you mean in my VS 2019 project? How do I check the MSBuild log when I am building inside VS? I tested with the Client and it actually does what I want in the 2019 version (creates and connects to my hub using the SignalRConnection class), do you think there would still be a problem?craigbot

1 Answers

4
votes

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