无法加载文件或程序集'Microsoft.IdentityModel.Protocols.WsFederation',

7

我在将流水线添加到startup.cs后,仅出现此错误。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartupAttribute(typeof(InnovationInABoxWebApi.App_Start.Startup))]
namespace InnovationInABoxWebApi.App_Start
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}

这是一个package.json文件。
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
  <package id="bootstrap" version="3.0.0" targetFramework="net45" />
  <package id="jQuery" version="1.10.2" targetFramework="net45" />
  <package id="Microsoft.ApplicationInsights" version="2.2.0" targetFramework="net45" />
  <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.0.6" targetFramework="net45" />
  <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.2.0" targetFramework="net45" />
  <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.2.0" targetFramework="net45" />
  <package id="Microsoft.ApplicationInsights.Web" version="2.2.0" targetFramework="net45" />
  <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.2.0" targetFramework="net45" />
  <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.2.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.Cors" version="5.2.5" targetFramework="net451" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.5" targetFramework="net451" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.5" targetFramework="net451" />
  <package id="Microsoft.AspNet.WebApi.Cors" version="5.2.5" targetFramework="net451" />
  <package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.8" targetFramework="net45" />
  <package id="Microsoft.IdentityModel.Logging" version="5.2.1" targetFramework="net451" />
  <package id="Microsoft.IdentityModel.Tokens" version="5.2.1" targetFramework="net451" />
  <package id="Microsoft.Net.Compilers" version="1.3.2" targetFramework="net45" developmentDependency="true" />
  <package id="Microsoft.Owin" version="4.0.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="4.0.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Security" version="4.0.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Security.ActiveDirectory" version="4.0.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Security.Jwt" version="4.0.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Security.OAuth" version="4.0.0" targetFramework="net451" />
  <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="10.0.1" targetFramework="net451" />
  <package id="Owin" version="1.0" targetFramework="net451" />
  <package id="Respond" version="1.2.0" targetFramework="net45" />
  <package id="System.IdentityModel.Tokens.Jwt" version="5.2.1" targetFramework="net451" />
  <package id="WebGrease" version="1.5.2" targetFramework="net45" />
</packages>

完整错误信息

Could not load file or assembly 'Microsoft.IdentityModel.Protocols.WsFederation, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel.Protocols.WsFederation, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Source Error: 


 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.IdentityModel.Protocols.WsFederation, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.



WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].



Stack Trace: 



[FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel.Protocols.WsFederation, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   Microsoft.Owin.Security.ActiveDirectory.WsFedMetadataRetriever.GetSigningKeys(String metadataEndpoint, TimeSpan backchannelTimeout, HttpMessageHandler backchannelHttpHandler) +0
   Microsoft.Owin.Security.ActiveDirectory.WsFedCachingSecurityKeyProvider.RetrieveMetadata() +146
   Microsoft.Owin.Security.ActiveDirectory.WsFedCachingSecurityKeyProvider..ctor(String metadataEndpoint, ICertificateValidator backchannelCertificateValidator, TimeSpan backchannelTimeout, HttpMessageHandler backchannelHttpHandler) +296
   Owin.WindowsAzureActiveDirectoryBearerAuthenticationExtensions.UseWindowsAzureActiveDirectoryBearerAuthentication(IAppBuilder app, WindowsAzureActiveDirectoryBearerAuthenticationOptions options) +163
   InnovationInABoxWebApi.App_Start.Startup.ConfigureAuth(IAppBuilder app) in C:\Users\valencil\source\repos\InnovationInABoxWebApi2\InnovationInABoxWebApi\App_Start\Startup.Auth.cs:15
   InnovationInABoxWebApi.App_Start.Startup.Configuration(IAppBuilder app) in C:\Users\valencil\source\repos\InnovationInABoxWebApi2\InnovationInABoxWebApi\Startup.cs:15

3
请尝试通过Nuget安装此软件包:Install-Package Microsoft.IdentityModel.Protocols.WsFederation -Version 5.2.0.0 - Sujit.Warrier
谢谢,那个起作用了。 - Luis Valencia
以下是有关编程的内容,请将其翻译成中文。仅返回翻译后的文本: - Luis Valencia
2个回答

10

尝试通过此方式安装该软件包:

Nuget Install-Package Microsoft.IdentityModel.Protocols.WsFederation -Version 5.2.0.0 

我遇到了与@Luis Valencia相同的问题。我已经按照您的建议安装了NuGet包Microsoft.IdentityModel.Protocols.WsFederation。但它并没有解决我的问题。奇怪的是,这个项目今天早上还能正常工作,现在却不能了。 - Rod
@Rod:我也是这样。请在“程序包管理器控制台”中确认您已设置默认项目,然后重复执行“Install-Package”命令。 - BillVo
@BillVo,我遇到了一个奇怪的问题。尽管在6月5日安装 Microsoft.IdentityModel.Protocols.WsFederation 后出现了问题,但第二天我可以正常使用它。我不明白为什么会有这样的差别,但由于我无法再次复制该问题,所以我就默认它是正常的。 - Rod
现在,请使用Nuget安装Microsoft.IdentityModel.Protocols.WsFederation -Version 5.2.0.0。 - chase huber

0
  1. 验证 Web.Config 中的 dependentAssembly "Microsoft.IdentityModel.Protocols.WsFederation" 的旧版本号和新版本号。Visual Studio 默认模板在版本号末尾添加了一个额外的 "0"。 例如:实际值:oldVersion="0.0.0.0-5.2.1.0.0" newVersion="5.2.1.0.0" 请将值替换为:oldVersion="0.0.0.0-5.2.1.0" newVersion="5.2.1.0"

  2. 打开 Package Manager 控制台并运行 Install-Package Microsoft.IdentityModel.Protocols.WsFederation -Version 5.2.1.0

这一步解决了我的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接