调用 Microsoft.Owin.Cors 后无法加载 System.Web.Cors 程序集 [英] Can't load System.Web.Cors assembly after call to Microsoft.Owin.Cors

查看:32
本文介绍了调用 Microsoft.Owin.Cors 后无法加载 System.Web.Cors 程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在解决方案资源管理器中检查 System.Web.Cors 程序集参考时,Version5.2.3.0.Specific Version 属性设置为 False.该路径是到本地项目 bin 文件夹.从文件资源管理器检查 .dll 属性时,文件的产品版本和文件版本.也是 5.2.3.

When I check the System.Web.Cors assembly reference in the Solution Explorer, the Version is 5.2.3.0. The Specific Version property is set to False. The path is to the local project bin folder. When checking the .dll properties from the File Explorer, the file's product version and file version. is also 5.2.3.

我的Web.config:

<dependentAssembly>
    <assemblyIdentity name="System.Web.Cors" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>

我的packages.config(我认为麻烦的程序集是Microsoft.AspNet.WebApi.Cors,但我在这里添加了另一个名称相似的程序集):

My packages.config (I think the troublesome assembly is Microsoft.AspNet.WebApi.Cors, but I included another one here with a similar name):

<package id="Microsoft.AspNet.Cors" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Cors" version="5.2.3" targetFramework="net452" />

Startup.cs

app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

这里是完整的错误:

System.IO.FileLoadException was unhandled by user code
  FileName=System.Web.Cors, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
  FusionLog==== Pre-bind state information ===
LOG: DisplayName = System.Web.Cors, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///P:/project-z4a/project-z4a/
LOG: Initial PrivatePath = P:project-z4aproject-z4ain
Calling assembly : Microsoft.Owin.Cors, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: P:project-z4aproject-z4aweb.config
LOG: Using host configuration file: D:DocumentsIISExpressconfigaspnet.config
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config.
LOG: Post-policy reference: System.Web.Cors, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Users/*****/AppData/Local/Temp/Temporary ASP.NET Files/root/f8163156/5c96d267/System.Web.Cors.DLL.
LOG: Attempting download of new URL file:///C:/Users/*****/AppData/Local/Temp/Temporary ASP.NET Files/root/f8163156/5c96d267/System.Web.Cors/System.Web.Cors.DLL.
LOG: Attempting download of new URL file:///P:/project-z4a/project-z4a/bin/System.Web.Cors.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

  HResult=-2146234304
  Message=Could not load file or assembly 'System.Web.Cors, 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)
  Source=Microsoft.Owin.Cors
  StackTrace:
       at Microsoft.Owin.Cors.CorsOptions.get_AllowAll()
       at z4a_dsa.Startup.Configuration(IAppBuilder app) in P:project-z4aproject-z4aStartup.cs:line 23
  InnerException: 

所以,我可以看到它在期待 v5.0.0.0,但我看不到在哪里或为什么需要这个版本.

So, I can see it's expecting v5.0.0.0, but I can't see where where or why calling for this version.

我已完成以下步骤来调试此错误.在列出的每一次尝试之后,我都进行了清理,然后重新构建了该项目.尝试每个步骤后,错误仍未改变.

I've done the following steps to debug this error. After each of the listed attempts, I cleaned, then rebuilt the project. The error hasn't changed after trying each of these steps.

  • 更新包
  • 安装包 Microsoft.AspNet.WebApi.Cors
  • Uninstall-Package Microsoft.AspNet.WebApi.Cors,然后 Install-Package Microsoft.AspNet.WebApi.Cors
  • Uninstall-Package Microsoft.AspNet.WebApi.Cors,然后Install-Package Microsoft.AspNet.WebApi.Cors -Version 5.2.3
  • 通过包管理器窗口将 Microsoft.AspNet.WebApi.Cors 降级到 v5.0.0.0.
  • Update-Package
  • Install-Package Microsoft.AspNet.WebApi.Cors
  • Uninstall-Package Microsoft.AspNet.WebApi.Cors, then Install-Package Microsoft.AspNet.WebApi.Cors
  • Uninstall-Package Microsoft.AspNet.WebApi.Cors, then Install-Package Microsoft.AspNet.WebApi.Cors -Version 5.2.3
  • Downgraded Microsoft.AspNet.WebApi.Cors to v5.0.0.0 via the Package Manager Window.

我还不是 .NET 专家,这是每次使用不同程序集时第 4 次出现完全相同的错误,因为我开始了一个新的空项目,并检查了 Web Api.我将 z4a-foundation-scaffold-auth 包安装到我的项目中.我一定会很感激在这里解释我的知识差距!

I'm not an expert in .NET yet, and this is the 4th occurrence of the same exact error with a different assembly each time, since I started a fresh empty project with Web Api checked. And I installed the z4a-foundation-scaffold-auth package into my project. I would definitely appreciate some explanation of my gaps in knowledge here!

EDIT:使用 ILDASM.exe 查看 Microsoft.Owin.Cors 程序集.发现它在其清单定义中指定了 System.Web.Cors v5.0.0.0.我想我现在的问题是如何解决这个问题?

EDIT: Used ILDASM.exe to look at Microsoft.Owin.Cors assembly. Found it specified System.Web.Cors v5.0.0.0 in its manifest definition. I guess my question is now how to remedy this?

推荐答案

原来 System.Web.Cors.dll 不是来自 Microsoft.AspNet.WebApi.Cors代码> 包.它来自 Microsoft.AspNet.Cors 包.

Turns out System.Web.Cors.dll does not come from the Microsoft.AspNet.WebApi.Cors package. It comes from the Microsoft.AspNet.Cors package.

Install-Package Microsoft.AspNet.Cors -Version 5.0.0

这解决了即时错误.

如果您遇到需要 System.Web.Cors.dll 的两个不同版本的情况,我建议您使用以下解决方案:

In case you have a scenario in which you need two different versions of the System.Web.Cors.dll, I'd suggest this solution:

  1. 使用包管理器,将 Microsoft.AspNet.Cors 的版本更改为 Microsoft.Owin.Cors 在其清单定义中请求的版本.
  2. 使用 Visual Studio 的开发人员命令提示符(以管理员身份运行),导航到新版本 Microsoft.AspNet.Cors 的包文件夹,其中 *System.Web.Cors.dll**居住.
  3. 运行以下命令:gacutil -i System.Web.Cors.dll.
  4. 返回包管理器并将 Microsoft.AspNet.Cors 更改回您最初想要的版本.
  1. Using the Package Manager, change the version of Microsoft.AspNet.Cors to the version that Microsoft.Owin.Cors requests in its manifest definition.
  2. Using the Developer Command Prompt for Visual Studio (run as admin), navigate to the package folder for the newly versioned Microsoft.AspNet.Cors where the *System.Web.Cors.dll** resides.
  3. Run the following command: gacutil -i System.Web.Cors.dll.
  4. Go back to the Package Manager and change Microsoft.AspNet.Cors back to the version you originally wanted.

此方法只是将所需版本的 .dll 文件拉入您的解决方案的包文件夹中.然后使用 gacutil.exe 将此版本的 .dll 添加到全局程序集缓存中.Visual Studio 首先在 GAC 中探查所需的 .dll 版本,然后在您的本地项目中探查.

This method simply pulls the desired version of the .dll file into your Solution's packages folder. Then you use gacutil.exe to add this version of the .dll to your Global Assembly Cache. Visual Studio probes for the desired .dll versions first in the GAC, then in your local project.

这篇关于调用 Microsoft.Owin.Cors 后无法加载 System.Web.Cors 程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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