Visual Studio 2017 - 无法加载文件或程序集“System.Runtime,Version=4.1.0.0"或其依赖项之一 [英] Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies

查看:56
本文介绍了Visual Studio 2017 - 无法加载文件或程序集“System.Runtime,Version=4.1.0.0"或其依赖项之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 2017 并尝试创建一个 .Net Standard 1.5 库并在 .Net 4.6.2 nUnit 测试项目中使用它.

I am using Visual Studio 2017 and am trying to create a .Net Standard 1.5 library and use it in a .Net 4.6.2 nUnit test project.

我收到以下错误...

无法加载文件或程序集 'System.Runtime, Version=4.1.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其之一依赖关系.系统找不到指定的文件.

Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

我尝试了以下方法:

  1. 参考标准库作为项目参考.错误:给我上一个错误.
  2. 为我的 Std 库创建一个 NuGet pkg 并引用它.错误:类型是 System.String,需要 System.String.这是因为 System.Runtime 最终被项目引用,并且它具有所有标准类型的定义.
  3. 参考 NuGet pkg NetStandard.Library. 错误:给我与 # 相同的错误(类型是 System.String,需要 System.String").注意:在执行此操作之前,我从项目中清除了所有 NuGet 包,然后仅添加了 nUnit 和 NetStandard.Library 包(安装了 45 个其他包).
  1. Reference Std library as project reference. Error: gives me the previous error.
  2. Create a NuGet pkg for my Std library and reference that. Error: The type is System.String, expecting System.String. This is because System.Runtime ended up getting referenced by the project and it has definitions for all the standard types.
  3. Reference NuGet pkg NetStandard.Library. Error: give me the same error as # ("The type is System.String, expecting System.String"). NOTE: Before I did this, I cleared ALL NuGet packages from the project and then added just the nUnit and NetStandard.Library packages (which installed 45 other packages).

这是一个错误吗?有解决办法吗?任何帮助表示赞赏.

Is this a bug? Is there a work-around? Any help is appreciated.

推荐答案

我遇到了同样的问题,但没有找到可行的解决方案.我对这个问题的解决方案是:检查 App.config 和 packages.config 以查看版本是否匹配.

I had the same problem and no suggested solutions that I found worked. My solution for this issue was: Check App.config and packages.config to see if the versions match.

最初我的 app.config 包含:

Originally my app.config contained:

<dependentAssembly>
  <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
</dependentAssembly>

但是 packages.config 包含:

But the packages.config contained:

<package id="System.Runtime" version="4.3.0" targetFramework="net461" requireReinstallation="true" />

我修改了 app.config 条目以匹配新版本的 packages.config:

I modified the app.config entry to match packages.config for the newVersion:

<dependentAssembly>
  <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.3.0" />
</dependentAssembly>

修改后问题解决了.

这篇关于Visual Studio 2017 - 无法加载文件或程序集“System.Runtime,Version=4.1.0.0"或其依赖项之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆