无法在Visual Studio WebApi项目

时间:2017-08-29 14:41:14

标签: c# visual-studio asp.net-web-api asp.net-web-api2 nuget-package

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

  

无法加载文件或程序集&System; Run.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软件包,是webapi项目的一部分。

观察预绑定状态信息,表明正在从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没有在项目的参考文献中显示。如果我手动添加它会得到一个黄色图标(失败)。

这里有什么问题?我还能检查什么?

1 个答案:

答案 0 :(得分:0)

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

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

  

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

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