asp.netsignalrvisual-studio-extensionsvsixsignalr-client

Using aspnet core SignalR client for VSIX project


I have an issue when I try to build connection for SignalR hub from VSIX project.

Visual studio 2022

VSIX project: TargetFramework: .Net framework 4.7.2

Signal R lib Lib name: Microsoft.AspNetCore.SignalR.Client version: 7.0.5

// MyCoolCommand.cs

/// <summary>
/// Command handler
/// </summary>
internal sealed class MyCoolCommand
{
   // some init code. I did change nothing
   private void Execute(object sender, EventArgs e)
   {
      var url = "http://localhost:9200/myHub";

      // will fail
      var connection = new HubConnectionBuilder()
         .WithUrl(url)
         .WithAutomaticReconnect()
         .Build();
    }
}

Exception info:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Options, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.'

How to repeat in your local machine:

  1. create VSIX project

  2. add command

  3. add Microsoft.AspNetCore.SignalR.Client from nuger

  4. in your command copy code from this example

  5. run

  6. I tried to change .net framework version - didn't helped

  7. Microsoft.Extensions.Options is one of sub deps for 'Microsoft.AspNetCore.SignalR.Client'. I double checked and this lib is exist in the output after build.

  8. I also tried to add Microsoft.Extensions.Options manually to the place where devenv.exe lives. after this I started to see the same exception but in this time System.Runtime is missing.

I think it somehow releated with runtime.


Solution

  • Answer: In my case changing the version of signal r client helped. From 7.0.5 to 7.0.0.

    Maybe it somehow related with avaliable runtime on your machine.