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
问题描述
我正在使用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.
我遇到以下错误...
I am getting the following error...
无法加载文件或程序集'System.Runtime,版本= 4.1.0.0,
文化=中立,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.
我尝试了以下操作:
- 参考Std库作为项目参考。错误:给我上次错误。
- 为此创建NuGet pkg我的Std库并将其引用。错误:类型为System.String,需要System.String。这是因为System.Runtime最终被项目引用,并且具有所有标准类型的定义。
- 参考NuGet pkg NetStandard.Library。错误:给我与#相同的错误(类型为System.String,需要System.String)。注意:在执行此操作之前,我从项目中清除了所有NuGet软件包,然后仅添加了nUnit和NetStandard.Library软件包(已安装了45个其他软件包)。
- Reference Std library as project reference. Error: gives me the previous error.
- 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.
- 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条目以匹配newVersion的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屋!