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

Mar*_*cus 7 .net c# asp.net-mvc visual-studio owin

我有一个带有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
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的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>
Run Code Online (Sandbox Code Playgroud)

我尝试添加绑定重定向:

<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> 
Run Code Online (Sandbox Code Playgroud)

无法理解为什么这不起作用,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之外的任何其他版本的引用.

我卡住了,有什么想法?

Mar*_*cus 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" />
Run Code Online (Sandbox Code Playgroud)

显然,即使Microsoft.AspNet.Identity.Owin需要> = v2.0 Microsoft.Owin.Security.OAuth,但v3 + Microsoft.Owin.Security.OAuth会破坏兼容性(主要版本不一致).

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

VS2013 + Ultimate用户的一个提示是在探索包依赖关系时使用NuGet包Visualizer.