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.
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>
But the packages.config contained:
<package id="System.Runtime" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
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>
After the change, the issue was resolved.
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.
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.
To fix this, you need to ensure your .NET 4.x csproj file is pointing to current build tools (at least 14):
<Project ToolsVersion="15.0">...
The below should no longer be needed, it was fixed around VS 15.3:
There was a known bug in VS2017, specifically in NuGet 4.0.
To work around the bug, you'll need to open up the .csproj file for your .NET 4.x project and add this snippet:
<ItemGroup>
<PackageReference Include="Legacy2CPSWorkaround" Version="1.0.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
NuGet 4.x brings with it the "package reference" -- no more packages.config -- but the old 4.x pipeline was not fully updated at the time of VS2017's launch. The above snippet seems to "wake up" the build system to correctly include package references from dependencies.
Trust me, I am not joking. Remove all the System.Runtime dependencies from your app.config and it will start working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With