【发布时间】:2014-03-20 21:13:22
【问题描述】:
我使用所有默认值在 VS Express 2013 中创建了一个基本的 ASP.NET Web Api 应用程序。我添加了一个控制器,它会按照我的意愿返回 XML。
只要我安装了 CORS 包:
Install-Package Microsoft.AspNet.WebApi.Cors -Pre
我什至不能再运行应用程序了:
An exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll and wasn't handled before a managed/native boundary
Additional information: Could not load file or assembly 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
我遵循了这篇博文中的所有说明:http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api,其中没有说明这个问题。
我尝试使用以下方式更新 Web API:
Install-Package Microsoft.AspNet.WebApi -Pre
但不幸的是问题仍然存在
在项目中,我使用的是 WebApi.Hal,它依赖于 Web.Api 5.0 及更高版本。是否有任何重大变化?
重现问题的绝对最小值
- 创建新的、完全空的 Web API 项目 n VS Express for Web 2013
- 添加一个控制器并测试它的工作原理
- 安装 CORS
- 文件加载错误 - 控制器不再工作
-
升级 Web Api - 修复问题
安装包 Microsoft.AspNet.WebApi -Pre
- 安装 WebApi.Hal - 再次出现同样的错误
我可以使用不会杀死其他所有东西的旧版本 CORS 库吗?
详细的堆栈跟踪
=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http.Formatting, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:
LOG: Initial PrivatePath = C
Calling assembly : WebApi.Hal, Version=2.2.0.18, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:
LOG: Using host configuration file: C:\
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Net.Http.Formatting, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C: Files/root/aa0e7960/9dfdb45e/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C: Files/root/aa0e7960/9dfdb45e/System.Net.Http.Formatting/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C:/CORSTest/CORSTest/bin/System.Net.Http.Formatting.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
【问题讨论】:
-
在 VS2015 中 - System.Web.Cors dll 仍然存在此问题,并且已尝试上述所有方法...当前版本的软件包是 6.0.1 预览版。但由于与帮助页面 dll 冲突,无法升级到该版本
标签: c# asp.net .net asp.net-web-api