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...
I encounter this issue recently and I tried many things mentioned in this thread and others. I added package reference for "System.Runtime"
by nuget package manager, fixed the binding redicts in app.config
, and make sure that app.config
and package.config
have the same version for the assembly. However, the problem persisted.
Finally, I removed the <dependentAssembly>
tag for the assembly and the problem dissappeared. So, try removing the following in your app.config
.
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.1.0" />
</dependentAssembly>
Edit:
After I update .NET framework to 4.7.2, the problem resurfaced. I tried the above trick but it didn't work. After wasting many hours, I realized the problem is occurring because of an old System.Linq
reference in app.config. Therefore, either remove or update all Linq references also to get rid of this problem.
Seems like the issue is caused when there is version conflict between packages.config and app.config. In app.config you have assembly binding redirects automatically generated by thing called "AutoGenerateBindingRedirects". When enabled each time you download nuget package it will, additionaly to making new entry in packages.config, add this binding redirect information to app.config, what's the purpose of this is explained here: Assembly Binding redirect: How and Why?
There you can read what user @Evk wrote:
Why are binding redirects needed at all? Suppose you have application A that references library B, and also library C of version 1.1.2.5. Library B in turn also references library C, but of version 1.1.1.0. Now we have a conflict, because you cannot load different versions of the same assembly at runtime. To resolve this conflict you might use binding redirect, usually to the new version
So, QUICK FIX: Remove all entries in app.config.
In my case just by doing that program started working, but it will probably work only if you don't have any version conflicts of the same assembly at runtime.
If you do have such conflict you should fix these version numbers in app.config to match actually used versions of assemblies, but manual process is painful, so I suggest to auto-generate them again by opening Package Manager Console and perform packages reinstallation by typing Update-Package -reinstall
This issue has many causes... in my case the problem was that in my web.config
a tag adding the System.Runtime
assembly:
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
but one package also added the same assembly as dependency with other version:
<package id="System.Runtime" version="4.3.0" targetFramework="net47" />
removing the <add assembly>
tag from my web.config
resolved the issue.
This issue happens when you reference a .NET Standard project from a .NET 4.x project: none of the .NET Standard project's nuget package references are brought in as dependencies.
I resolved by add System.Runtime 4.3
and NETStandard.Library package and !!important!! I use refactor tool to look up the System.Runtime.dll version, It is 4.1.1.1
not 4.3
and then add an bindingRedirect in .config
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.1.1.1" />
</dependentAssembly>
I had an issue with this in an NUnit 2.6.4 project targeting dotnet framework 4.6.2. I ran into that System.Runtime FileNotFound
error trying to use Humanizer.
I fixed my error by installing NetStandard.Library into my unit test project.
Before running the unit tests, just remove the runtime tags from app.config file. Problem will be solved.