简体   繁体   中英

Failure to load System.runtime dll on Visual studio WebApi project

When i run the portal it gives the following error:

Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

=== Pre-bind state information ===
LOG: DisplayName = System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///D:/.....
LOG: Initial PrivatePath = ....\bin
Calling assembly : System.Runtime.CompilerServices.Unsafe, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: ....\web.config
LOG: Using host configuration file: ....\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.1.0.
LOG: Post-policy reference: System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: The same bind was seen before, and was failed with hr = 0x80131040. 

System.Runtime is a Microsoft package that is part of the webapi project.

Observing the Pre-bind state information it shows that the system.runtime dll is being called from System.Runtime.CompilerServices.Unsafe dll. Also the following redirect is made:

LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.1.0.

The System.Runtime Package version is 4.3.0 and generates dll version 4.1.1.0. This is my first doubt. I thing dll version should be 4.3.0.0 but inspecting with ILSpy it shows that the Assembly version attribute is 4.1.1.0

Web config redirect is correct, it redirects the call to version 4.0.0.0 to version 4.1.1.0 as show in the Pre-bind log

The odd thing is that System.Runtime doesn't show in the references of the project. If i add it manually it gets an yellow icon (fail).

What is wrong here? What more can i check?

Found out that the problem was caused by a version conflict and not by an incompatible version as i expected.

The follow build warning exposed the conflict. Just need to double click on the warning message to fix the binding session on the web conflict.

Warning Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: ...

I am not sure if Visual studio will be able to detect all build conflicts,so the absence of this warning may still be caused by the same error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM