安装CORS后无法加载文件 [英] Cannot load file after installing CORS

查看:60
本文介绍了安装CORS后无法加载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用所有默认设置在VS Express 2013中创建了一个基本的ASP.NET Web Api应用程序.我添加了一个控制器,它可以根据需要返回XML.

I have created a basic ASP.NET Web Api Application inside VS Express 2013 using all of the defaults. I added a controller and it returns XML just as I want.

一旦我安装了CORS软件包:

As soon as I install the CORS package:

Install-Package Microsoft.AspNet.WebApi.Cors -Pre

我什至无法运行该应用程序:

I can't even run the application anymore:

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 中对此问题一无所知.

I followed all of the instructions on this blog post: http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api which says nothing about this issue.

我尝试使用以下方法更新Web API:

I tried updating Web API with:

Install-Package Microsoft.AspNet.WebApi -Pre

但不幸的是,问题仍然存在

But still the problem persists unfortunately

在项目中,我使用的是WebApi.Hal,它依赖于Web.Api 5.0及更高版本.也许有重大变化吗?

In the project I am using WebApi.Hal which depends on Web.Api 5.0 and greater. Are there any breaking changes perhaps?

重现问题的绝对最小值

  1. 为Web 2013创建新的,完全为空的Web API项目VS Express
  2. 添加控制器并对其进行测试
  3. 安装CORS
  4. 文件加载错误-控制器不再起作用
  5. 升级Web Api-修复问题

  1. Create new, completely empty, Web API project n VS Express for Web 2013
  2. Add a controller and test it works
  3. Install CORS
  4. File load error - controller doesn't work anymore
  5. Upgrade Web Api - fixes problem

安装软件包Microsoft.AspNet.WebApi -Pre

Install-Package Microsoft.AspNet.WebApi -Pre

我可以使用不能杀死其他所有功能的旧版CORS库吗?

Can I use an old version of the CORS library that doesn't kill everything else?

详细的堆栈跟踪

=== 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.

推荐答案

两步来解决问题

  1. 添加

dependentAssemblyassemblyIdentity name ="System.Web.Http" publicKeyToken ="31bf3856ad364e35"bindingRedirect oldVersion ="0.0.0.0-5.0.0.0" newVersion ="5.0.0.0"dependentAssembly

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

to web.config

  1. 转到工具/库打包的管理器/管理Nuget包"以获取解决方案,然后单击"Microsoft ASP.Net MVC",然后单击更新".

希望有帮助

谭阮

这篇关于安装CORS后无法加载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆