[英]Can't load System.Web.Cors assembly after call to Microsoft.Owin.Cors
When I check the System.Web.Cors
assembly reference in the Solution Explorer, the Version
is 5.2.3.0 .当我在解决方案资源管理器中检查System.Web.Cors
程序集参考时, Version
是5.2.3.0 。 The Specific Version
property is set to False
. Specific Version
属性设置为False
。 The path is to the local project bin folder.该路径是到本地项目 bin 文件夹。 When checking the .dll properties from the File Explorer, the file's product version and file version.从文件资源管理器检查 .dll 属性时,文件的产品版本和文件版本。 is also 5.2.3 .也是5.2.3 。
My Web.config :我的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>
My packages.config (I think the troublesome assembly is Microsoft.AspNet.WebApi.Cors
, but I included another one here with a similar name):我的packages.config (我认为麻烦的程序集是Microsoft.AspNet.WebApi.Cors
,但我在这里包含了另一个名称相似的程序集):
<package id="Microsoft.AspNet.Cors" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Cors" version="5.2.3" targetFramework="net452" />
Error is thrown on this line in Startup.cs Startup.cs 中的这一行抛出错误
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
Here is the full error:这是完整的错误:
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-z4a\project-z4a\bin
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-z4a\project-z4a\web.config
LOG: Using host configuration file: D:\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.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-z4a\project-z4a\Startup.cs:line 23
InnerException:
So, I can see it's expecting v5.0.0.0, but I can't see where where or why calling for this version.所以,我可以看到它在期待 v5.0.0.0,但我看不到在哪里或为什么需要这个版本。
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.尝试这些步骤中的每一个后,错误都没有改变。
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
,然后Install-Package Microsoft.AspNet.WebApi.Cors
Uninstall-Package Microsoft.AspNet.WebApi.Cors
, then Install-Package Microsoft.AspNet.WebApi.Cors -Version 5.2.3
Uninstall-Package Microsoft.AspNet.WebApi.Cors
,然后Install-Package Microsoft.AspNet.WebApi.Cors -Version 5.2.3
Microsoft.AspNet.WebApi.Cors
to v5.0.0.0
via the Package Manager Window.通过包管理器窗口将Microsoft.AspNet.WebApi.Cors
降级到v5.0.0.0
。 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.我还不是 .NET 专家,这是每次使用不同程序集时第 4 次出现完全相同的错误,因为我开始了一个新的空项目并检查了Web Api
。 And I installed the z4a-foundation-scaffold-auth
package into my project.我将z4a-foundation-scaffold-auth
包安装到我的项目中。 I would definitely appreciate some explanation of my gaps in knowledge here!我一定会很感激我在这里的知识差距的一些解释!
EDIT : Used ILDASM.exe to look at Microsoft.Owin.Cors
assembly.编辑:使用 ILDASM.exe 查看Microsoft.Owin.Cors
程序集。 Found it specified System.Web.Cors v5.0.0.0
in its manifest definition.发现它在其清单定义中指定了System.Web.Cors v5.0.0.0
。 I guess my question is now how to remedy this?我想我现在的问题是如何解决这个问题?
Turns out System.Web.Cors.dll does not come from the Microsoft.AspNet.WebApi.Cors
package.原来System.Web.Cors.dll不是来自Microsoft.AspNet.WebApi.Cors
包。 It comes from the Microsoft.AspNet.Cors
package.它来自Microsoft.AspNet.Cors
包。
Install-Package Microsoft.AspNet.Cors -Version 5.0.0
This resolved the immediate error.这解决了直接错误。
In case you have a scenario in which you need two different versions of the System.Web.Cors.dll , I'd suggest this solution:如果您有需要System.Web.Cors.dll 的两个不同版本的场景,我建议使用此解决方案:
Microsoft.AspNet.Cors
to the version that Microsoft.Owin.Cors
requests in its manifest definition.使用软件包管理器,版本改变Microsoft.AspNet.Cors
的版本Microsoft.Owin.Cors
了清单中定义的请求。Microsoft.AspNet.Cors
where the *System.Web.Cors.dll** resides.使用 Visual Studio 的开发人员命令提示符(以管理员身份运行),导航到 *System.Web.Cors.dll** 所在的新版本Microsoft.AspNet.Cors
的包文件夹。gacutil -i System.Web.Cors.dll
.运行以下命令: gacutil -i System.Web.Cors.dll
。Microsoft.AspNet.Cors
back to the version you originally wanted.返回包管理器并将Microsoft.AspNet.Cors
更改回您最初想要的版本。 This method simply pulls the desired version of the .dll file into your Solution's packages folder.此方法只是将所需版本的 .dll 文件拉入解决方案的包文件夹中。 Then you use gacutil.exe
to add this version of the .dll to your Global Assembly Cache.然后使用gacutil.exe
将此版本的 .dll 添加到全局程序集缓存中。 Visual Studio probes for the desired .dll versions first in the GAC, then in your local project. Visual Studio 首先在 GAC 中探查所需的 .dll 版本,然后在本地项目中探查。
run this command into PM (package manager)将此命令运行到 PM(包管理器)中
Install-Package Microsoft.AspNet.Cors -Version 5.2.3.0安装包 Microsoft.AspNet.Cors -Version 5.2.3.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.