无法在Visual Studio Web Api项目上加载System.runtime dll

问题描述 投票:0回答:1

当我运行门户网站时,它会出现以下错误:

无法加载文件或程序集'System.Runtime,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。 (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是一个Microsoft包,它是web api项目的一部分。

观察预绑定状态信息,它显示从system.runtime dll调用System.Runtime.CompilerServices.Unsafe dll。还进行了以下重定向:

日志:在应用程序配置文件中找到重定向:4.0.0.0重定向到4.1.1.0。

System.Runtime包版本是4.3.0并生成DLL版本4.1.1.0。这是我的第一个怀疑。我的dll版本应该是4.3.0.0但是使用ILSpy进行检查它表明Assembly版本属性是4.1.1.0

Web配置重定向是正确的,它将调用重定向到版本4.0.0.0到版本4.1.1.0,如预绑定日志中所示

奇怪的是,System.Runtime没有在项目的参考文献中显示。如果我手动添加它会得到一个黄色图标(失败)。

这有什么不对?我还能检查什么?

c# visual-studio asp.net-web-api asp.net-web-api2 nuget-package
1个回答
0
投票

发现问题是由版本冲突引起的,而不是由我预期的不兼容版本引起的。

跟随构建警告暴露了冲突。只需双击警告消息即可修复Web冲突上的绑定会话。

警告发现同一依赖程序集的不同版本之间存在冲突。在Visual Studio中,双击此警告(或选择它并按Enter键)以修复冲突;否则,将以下绑定重定向添加到应用程序配置文件中的“runtime”节点:...

我不确定Visual Studio是否能够检测到所有构建冲突,因此缺少此警告可能仍然是由同一错误引起的。

© www.soinside.com 2019 - 2024. All rights reserved.