【问题标题】:Could not load file or assembly Microsoft.Owin.Security.OAuth, Version=2.0.0.0无法加载文件或程序集 Microsoft.Owin.Security.OAuth,版本 = 2.0.0.0
【发布时间】:2015-09-03 12:49:48
【问题描述】:

我有一个带有 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.

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

【问题讨论】:

  • 添加到packages.config 是不够的,您是否在.cproj 文件中添加了对该dll 的引用?
  • 检查您的 bin 文件夹中是否有 Microsoft.Owin.Security.OAuth.dll。
  • “添加到 packages.config 还不够”是什么意思?您是否建议我使用包管理器控制台安装它,然后手动添加参考?那有什么意义呢?是的,3.0.1 版本的 DLL 在 Bin 文件夹中。

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


【解决方案1】:

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

问题是 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 需要 >= 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 包可视化工具。

【讨论】:

  • 您能否更正引用的文本:“即使 Microsoft.AspNet.Identity.Owin 需要 >= Microsoft.AspNet.Identity.Owin 的 v2.0,具有 Microsoft.AspNet.Identity 的 v3+ .Owin"
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2018-10-04
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    • 2016-07-19
    • 2012-03-14
    • 1970-01-01
    • 2018-05-24
    • 1970-01-01
    相关资源
    最近更新 更多