无法加载文件或程序集 Microsoft.Owin.Security.OAuth,版本 =2.0.0.0
Could not load file or assembly Microsoft.Owin.Security.OAuth, Version=2.0.0.0
我有一个带有 OAuth 身份验证的 MVC 项目,每次我尝试调试该项目时,我都会在配置 IAppBuilder 时收到 FileLoadException。我已经使用 PMC 安装了 Microsoft.Owin.Security.Oauth 的 3.0.1 版,但我猜某处仍然引用了旧版本的软件包,因为...
这是例外情况:
这是它被抛出的地方:
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app); //Exception is thrown here
}
}
这是我的 packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
<package id="CommonServiceLocator" version="1.3" targetFramework="net45" />
<package id="EntityFramework" version="6.0.0" targetFramework="net45" />
<package id="jQuery" version="1.10.2" targetFramework="net45" />
<package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
<package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.HelpPage" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Google" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Modernizr" version="2.6.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />
<package id="Unity" version="3.5.1404.0" targetFramework="net45" />
<package id="WebGrease" version="1.6.0" targetFramework="net45" />
</packages>
我试过这样添加 binding redirect:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" PublicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
</dependentAssembly>
不明白为什么这不起作用,Visual Studio 3.0.1 和 3.0.1.0 之间有区别吗?
我尝试删除 obj 和 bin 文件夹,清理项目并重建它们。
我尝试删除所有 nuget 包并恢复它们。
我尝试重新安装所有 Owin 软件包。
我使用 Agent Ransack 在我的整个源目录中搜索任何包含 Microsoft.Owin.Security.OAuth 的文件,但没有找到对版本 2.0.0.0 或除此之外的任何其他版本的引用正确的 3.0.1.0.
我卡住了,有什么想法吗?
检查您的参考资料。从所有地方删除 Microsoft.Owin.Security.OAuth,然后恢复所有 nuget 包。
好的,以防其他人遇到这个问题;
问题是 Microsoft.AspNet.Identity.Owin
包依赖于 Microsoft.Owin.Security.OAuth
并且版本不匹配。
<package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
显然,即使 Microsoft.AspNet.Identity.Owin 需要 Microsoft.Owin.Security.OAuth
的 >= v2.0,拥有 Microsoft.Owin.Security.OAuth
的 v3+ 也会破坏兼容性(主要版本不一致)。
更新 Microsoft.AspNet.Identity.Owin
包及其相邻的系列成员 Microsoft.AspNet.Identity.EntityFramework
和 Microsoft.AspNet.Identity.Core
后,我删除了所有包、bin 和 obj 文件夹并重建了解决方案。瞧!
VS2013+ Ultimate 用户的一个提示是在探索包依赖项时使用 NuGet 包可视化工具。
我有一个带有 OAuth 身份验证的 MVC 项目,每次我尝试调试该项目时,我都会在配置 IAppBuilder 时收到 FileLoadException。我已经使用 PMC 安装了 Microsoft.Owin.Security.Oauth 的 3.0.1 版,但我猜某处仍然引用了旧版本的软件包,因为...
这是例外情况:
这是它被抛出的地方:
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app); //Exception is thrown here
}
}
这是我的 packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
<package id="CommonServiceLocator" version="1.3" targetFramework="net45" />
<package id="EntityFramework" version="6.0.0" targetFramework="net45" />
<package id="jQuery" version="1.10.2" targetFramework="net45" />
<package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
<package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.HelpPage" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Google" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Modernizr" version="2.6.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />
<package id="Unity" version="3.5.1404.0" targetFramework="net45" />
<package id="WebGrease" version="1.6.0" targetFramework="net45" />
</packages>
我试过这样添加 binding redirect:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" PublicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
</dependentAssembly>
不明白为什么这不起作用,Visual Studio 3.0.1 和 3.0.1.0 之间有区别吗?
我尝试删除 obj 和 bin 文件夹,清理项目并重建它们。
我尝试删除所有 nuget 包并恢复它们。
我尝试重新安装所有 Owin 软件包。
我使用 Agent Ransack 在我的整个源目录中搜索任何包含 Microsoft.Owin.Security.OAuth 的文件,但没有找到对版本 2.0.0.0 或除此之外的任何其他版本的引用正确的 3.0.1.0.
我卡住了,有什么想法吗?
检查您的参考资料。从所有地方删除 Microsoft.Owin.Security.OAuth,然后恢复所有 nuget 包。
好的,以防其他人遇到这个问题;
问题是 Microsoft.AspNet.Identity.Owin
包依赖于 Microsoft.Owin.Security.OAuth
并且版本不匹配。
<package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
显然,即使 Microsoft.AspNet.Identity.Owin 需要 Microsoft.Owin.Security.OAuth
的 >= v2.0,拥有 Microsoft.Owin.Security.OAuth
的 v3+ 也会破坏兼容性(主要版本不一致)。
更新 Microsoft.AspNet.Identity.Owin
包及其相邻的系列成员 Microsoft.AspNet.Identity.EntityFramework
和 Microsoft.AspNet.Identity.Core
后,我删除了所有包、bin 和 obj 文件夹并重建了解决方案。瞧!
VS2013+ Ultimate 用户的一个提示是在探索包依赖项时使用 NuGet 包可视化工具。