无法加载文件或程序集Microsoft.Owin.Security.OAuth,Version = 2.0.0.0

时间:2015-09-03 12:49:48

标签: c# .net asp.net-mvc visual-studio owin

我有一个带有OAuth身份验证的MVC项目,每次我尝试调试项目时,在配置IAppBuilder时都会遇到FileLoadException。我已经使用PMC安装了Microsoft.Owin.Security.Oauth 3.0.1版,但我想某处仍然是对旧版本软件包的引用,因为......

这是一个例外:

enter image description here

这是抛出它的地方:

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

我被卡住了,有什么想法吗?

2 个答案:

答案 0 :(得分:14)

好的,以防万一其他人最终遇到这个问题;

问题是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的&gt; = v2.0,但Microsoft.Owin.Security.OAuth的v3 +会破坏兼容性(主要版本不一致)。

我更新Microsoft.AspNet.Identity.Owin软件包及其相邻的家庭成员Microsoft.AspNet.Identity.EntityFrameworkMicrosoft.AspNet.Identity.Core后,我删除了所有软件包,bin和obj文件夹并重新构建了解决方案。瞧!

VS2013 + Ultimate用户的提示是在探索包依赖项时使用NuGet Package Visualizer。

答案 1 :(得分:0)

检查您的参考资料。从任何地方删除Microsoft.Owin.Security.OAuth,然后恢复所有nuget包。

相关问题