Could not load file or assembly System.Runtime, Version=4.1.2.0

Andrey Korneyev picture Andrey Korneyev · Jan 29, 2018 · Viewed 27.1k times · Source

Suddenly, after adding some NuGet packages (mostly, related to ASPNET Identity), it started showing this error:

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

I have .Net Framework 4.7.1 targeted. I tried installing NuGet package System.Runtime 4.3.0, it didn't help. The web.config file has a reference:

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

There's no System.Runtime.dll in the bin folder.

Any ideas?

I use Visual Studio 2017 15.5.5.

UPDATE:

I use PackageReference entries in the .csproj file, so it's not the issue with the packages.config.

It seems like some dependencies are not loaded.

Answer

Paul Hatcher picture Paul Hatcher · Sep 2, 2018

I had this recently upgrading a project from net462 to net471, the issue in my case was some assembly redirects which were required by the net462 version but badly confused the net471.

The solution was to remove all the assembly redirect entries in web.config and let Visual Studio recompute them - they will appear as a warning which may be clicked on to re-add them to the web.config