我使用所有默认值在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 - 解决问题
安装包Microsoft.AspNet.WebApi -Pre
我可以使用旧版本的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.
答案 0 :(得分:2)
解决问题的两个步骤
添加
dependentAssembly assemblyIdentity name =“System.Web.Http”publicKeyToken =“31bf3856ad364e35” bindingRedirect oldVersion =“0.0.0.0-5.0.0.0”newVersion =“5.0.0.0” dependentAssembly
到web.config
希望有所帮助
Tam Nguyen
答案 1 :(得分:1)
问题是由于System.Net.Http.Formatting以及System.Web.Http程序集的版本冲突造成的。如果在构建代码后看到输出窗口,它会为您提供问题的解决方案。您所要做的就是将以下内容添加到Web.config文件中:
<dependentAssembly><assemblyIdentity name="System.Net.Http.Formatting" culture="neutral" publicKeyToken="31bf3856ad364e35" /><bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /></dependentAssembly>
<dependentAssembly><assemblyIdentity name="System.Web.Http" culture="neutral" publicKeyToken="31bf3856ad364e35" /><bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /></dependentAssembly>
答案 2 :(得分:0)
尝试重新安装:
Install-Package Microsoft.AspNet.WebApi.Cors
答案 3 :(得分:0)
Microsoft.AspNet.WebApi.Cors包将依赖关系引入版本5.2.3.0 dll,如上所示的用户sumit。我采取的路径是更新MVC项目proir 以安装CORS:
Install-Package Microsoft.AspNet.Mvc -Version 5.2.3
答案 4 :(得分:0)
解决此问题有两个步骤
更新asp.net mvc nuget包
安装包Microsoft.AspNet.Mvc -Version 5.2.3
使用新的dependentAssembly
更新web.configassemblyIdentity name =“System.Web.Http”publicKeyToken =“31bf3856ad364e35” bindingRedirect oldVersion =“0.0.0.0-5.0.0.0”newVersion =“5.2.3.0”