【问题标题】:InteropServices not found - unable to resolve未找到 InteropServices - 无法解决
【发布时间】:2022-01-23 11:24:35
【问题描述】:

我有点失落。我已经在这个项目上工作了 2 年,我决定重新安装我的操作系统以再次获得更流畅的工作体验。

我使用的安装程序是 Windows 10 和 Visual Studio 2022 社区版。项目本身是用.net 4.6.1编写的

自从重新安装操作系统后,我的 C# 项目在启动时崩溃。

Topshelf.HostFactory Error: 0 : The service terminated abnormally, 
System.IO.FileNotFoundException: Die Datei oder Assembly 
"System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, 
PublicKeyToken=(token)" oder eine Abhängigkeit wurde nicht gefunden.

我重新安装并更新了所有 NuGet 包,但我不知道如何修复 System.Runtime.InteropServices 错误。

根据其他资源InteropService 需要.net 4.7.1 但这并没有解决我的问题。

当我尝试手动添加 System.Runtime.InteropServices 时,它没有被列出(我猜是因为它一直在寻找 .NET Framework 4.6.1:

【问题讨论】:

  • 你在安装vs时勾选了正确的dotnet框架版本吗?
  • 我安装了 .net 6.x,之后又安装了 4.6.1 和 4.7.1
  • 还要检查App.config 中的程序集绑定:System.Runtime.InteropServices 可能存在版本重定向
  • 为什么要针对 .NET 4.6.1?我不相信有任何充分的理由继续使用那个旧版本。为什么不能改为以 .NET Framework 4.8 为目标?
  • @kyrylomyr <dependentAssembly> <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> </dependentAssembly> 在我的app.config

标签: c#


【解决方案1】:

好吧,我不太明白为什么,但是从控制台更新 NuGet 包与从界面更新是有区别的。界面对我不起作用。

Extra > NuGet Package Manager > Package Manager Console 下,您可以运行Update-Package。这对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 2019-06-24
    • 2019-01-14
    • 2017-11-09
    相关资源
    最近更新 更多