Using aspnet core SignalR client for VSIX project

huangapple go评论51阅读模式
英文:

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 related to runtime.

英文:

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.

答案1

得分: 0

你正在混合使用不兼容的.NET Framework和.NET CORE库。

这个链接解释了两者之间的差异。

请按照使用.NET Framework版本的文档。这里也有存储库 - https://github.com/SignalR/SignalR

英文:

You are mixing .NET Framework and .NET CORE libraries that are not compatible with each other.

This link explains the differences between the two.

Follow the documentation for using .NET Framework version. Here is the repo as well - https://github.com/SignalR/SignalR

答案2

得分: 0

在我的情况下,更改SignalR客户端的版本有所帮助。
从7.0.5改为7.0.0。

也许这与您的计算机上可用的运行时相关。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月9日 06:38:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76436138.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定