gpt4 book ai didi

c# - 安装 CORS 后无法加载文件

转载 作者:太空狗 更新时间:2023-10-29 19:44:03 25 4
gpt4 key购买 nike

我使用所有默认设置在 VS Express 2013 中创建了一个基本的 ASP.NET Web Api 应用程序。我添加了一个 Controller ,它会按照我的意愿返回 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 及更高版本。是否有任何重大变化?

重现问题的绝对最小值

  1. 在 VS Express for Web 2013 中创建新的、完全空的 Web API 项目
  2. 添加一个 Controller 并测试它是否正常工作
  3. 安装 CORS
  4. 文件加载错误 - Controller 不再工作
  5. 升级 Web Api - 修复问题

    安装包 Microsoft.AspNet.WebApi -Pre

  6. 安装 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.

最佳答案

两步解决问题

  1. 添加

    依赖程序集 assemblyIdentity name="System.Web.Http"publicKeyToken="31bf3856ad364e35" bindingRedirect oldVersion="0.0.0.0-5.0.0.0"newVersion="5.0.0.0" 依赖程序集

到 web.config

  1. 转到工具/Library Packed Manager/Manage Nuget Package For solution,然后单击 Microsoft ASP.Net MVC,然后单击 Update。

希望对你有帮助

谭阮

关于c# - 安装 CORS 后无法加载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22545211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com