调用Microsoft.Owin.Cors后无法加载System.Web.Cors总成 [英] Can't load System.Web.Cors assembly after call to Microsoft.Owin.Cors
问题描述
当我检查在Solution Explorer中,版本的
是<强> 5.2.3.0 。在 System.Web.Cors
集引用特定版本
属性设置为假
。路径是本地项目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-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:
所以,我可以看到它的预期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
-
卸载封装Microsoft.AspNet.WebApi.Cors
,那么安装封装Microsoft.AspNet.WebApi.Cors
-
卸载封装Microsoft.AspNet.WebApi.Cors
,那么安装封装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
, thenInstall-Package Microsoft.AspNet.WebApi.Cors
Uninstall-Package Microsoft.AspNet.WebApi.Cors
, thenInstall-Package Microsoft.AspNet.WebApi.Cors -Version 5.2.3
- Downgraded
Microsoft.AspNet.WebApi.Cors
tov5.0.0.0
via the Package Manager Window.
我不是一个专家在.NET着呢,这是每一次不同的装配完全相同的错误发生的第四次,因为我开始与网页API一个新的空项目
检查。我安装了 Z4A-基础脚手架-auth的
包到我的项目。我肯定会AP preciate这里我的知识缺口一些解释!
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!
修改:用于程序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:
- 使用软件包管理器,
Microsoft.AspNet.Cors
的版本更改为版本Microsoft.Owin.Cors $ C $在其清单定义C>请求。
- 使用的Visual Studio(以管理员身份运行)开发者命令提示符,导航到新版本的
Microsoft.AspNet.Cors
,其中* System.Web程序包文件夹.Cors.dll **所在。 - 运行以下命令:
GACUTIL -i System.Web.Cors.dll
- 返回到软件包管理器和变化
Microsoft.AspNet.Cors
回到你本来想的版本。
- Using the Package Manager, change the version of
Microsoft.AspNet.Cors
to the version thatMicrosoft.Owin.Cors
requests in its manifest definition. - 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. - Run the following command:
gacutil -i System.Web.Cors.dll
. - Go back to the Package Manager and change
Microsoft.AspNet.Cors
back to the version you originally wanted.
此方法只拉.dll文件所需的版本到您的解决方案的包文件夹中。然后,可以使用的Gacutil.exe
来这个版本的.dll文件添加到您的全局程序集缓存。 Visual Studio的探针所需的.dll文件的版本首先在GAC,然后在您的本地项目。
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屋!