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

我与影子孤独终老i 提交于 2020-06-08 04:41:35

问题


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.


回答1:


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




回答2:


My ASP.NET project was already on net471 in VS 15.8.4 when this started happening. When I attempted to update my existing NuGet packages to the latest versions I would receive this error upon launching the project in IIS Express.

BadImageFormatException: Could not load file or assembly 'System.Runtime' or one of its dependencies.

I was able to resolve this issue by modifying my project's web.config file.

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

Deleting the bindingRedirect lines for both of these System.Runtime dependencies resolved this issue in my project leaving me with this in my web.config.

  <dependentAssembly>
    <assemblyIdentity name="System.Runtime.Serialization.Primitives" publicKeyToken="B03F5F7F11D50A3A" culture="neutral" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  </dependentAssembly>



回答3:


The Assembly Binding's might be wrong.

DELETE the app.config or web.config AssemblyBinding sections. Then run this BindingRedirect in the Package Manager window:

Get-Project –All | Add-BindingRedirect

Optional: If you upgrade the framework version of all projects, you will need to reinstall all Nuget packages for all projects. To do that easily use this package managers script:

Get-Project –All | % { Get-Package -ProjectName $_.ProjectName | % { update-package $_.Id -reinstall -ProjectName $_.ProjectName -ignoreDependencies } }

Then run the Binding Redirect code above.




回答4:


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

The package System.Runtime is referenced but it needs to be installed.

  • In Visual Studio's menu, go to Tool > NuGet Package Manager > Manage NuGet Packages for Solution...

  • In the active NuGet - Solution window, go to the tab Installed, navigate to System.Runtime by Microsoft. Select with a single-click and look on the side window if a version exists for the project. If not, select the project and click Install.

  • Build solution.



来源:https://stackoverflow.com/questions/48503930/could-not-load-file-or-assembly-system-runtime-version-4-1-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!