简体   繁体   English

无法加载文件或程序集“Microsoft.IdentityModel.Clients.ActiveDirectory”

[英]Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory'

Following is the exact exception I am getting while running my .NET application.以下是我在运行 .NET 应用程序时遇到的确切异常。

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Generic.Helpers.dll Generic.Helpers.dll 中发生类型为“System.IO.FileNotFoundException”的未处理异常

Additional information: Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.28.1.741, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.附加信息:无法加载文件或程序集“Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.28.1.741, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或其依赖项之一。 The system cannot find the file specified.系统找不到指定的文件。

I have a console application which references a private assembly (.dll).我有一个引用私有程序集 (.dll) 的控制台应用程序。 The assembly is referencing to Microsoft.IdentityModel.Clients.ActiveDirectory, and I have also added a NuGet package for this in the project程序集引用了 Microsoft.IdentityModel.Clients.ActiveDirectory,我还在项目中为此添加了一个 NuGet 包

<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.1" targetFramework="net46" />

I can see the DLLs are being referenced correctly in the project.我可以看到在项目中正确引用了 DLL。 However, while running the application, I am getting an error as mentioned above.但是,在运行应用程序时,我收到了如上所述的错误。

Just to give you a brief overview of the class library project - this DLL has methods to connect to CRM web api.只是给你一个类库项目的简要概述 - 这个 DLL 有连接到 CRM web api 的方法。 This was working fine until last few days, and suddenly stopped working and throwing the error.直到最近几天,这一切正常,突然停止工作并抛出错误。

I am also consuming the same DLL in Azure function which is where it works perfectly fine.我还在 Azure 函数中使用了相同的 DLL,这正是它完美运行的地方。

Can anyone please suggest how to resolve this issue?任何人都可以请建议如何解决这个问题?

May be you don't have that specific version?可能你没有那个特定的版本? have you tried setting specific version to false in properties?您是否尝试在属性中将特定版本设置为 false?

NuGet won't handle the references in the program. NuGet 不会处理程序中的引用。 It just manages packages.它只是管理包。 This issue is with visual studio.这个问题与视觉工作室有关。 If NuGet updates some packages and your program asks for specific version, you will definitely get problems.如果 NuGet 更新了一些包并且你的程序要求特定版本,你肯定会遇到问题。

This was my situation and what worked for me:这是我的情况,对我有用:

I was using the Microsoft.IdentityModel.Clients.ActiveDirectory version 3.19 in a class library project but only had version 2.22 installed in the actual ASP.NET Web Application project.我在类库项目中使用了Microsoft.IdentityModel.Clients.ActiveDirectory 3.19 版,但在实际的 ASP.NET Web 应用程序项目中只安装了 2.22 版。 Upgrading to 3.19 in the web app project got me past the error.在 Web 应用程序项目中升级到 3.19 使我克服了错误。

This happens when nuget package versions are not same across all projects in the solution.当解决方案中的所有项目的 nuget 包版本不同时,就会发生这种情况。 Solution->Nuget Package manager-> browse for package解决方案-> Nuget 包管理器-> 浏览包

If there are different versions, make them uniform across projects.如果有不同的版本,让它们跨项目统一。 Issue should be solved.问题应该得到解决。

This happened with me when I downgraded my dll to version 2.28.3 from 3.19 to support "AcquireTokenByAuthorizationCode" functionality.当我将 dll 从 3.19 降级到版本 2.28.3 以支持“AcquireTokenByAuthorizationCode”功能时,就发生了这种情况。 After reinstallation it was still redirecting to version 3.19 because it was still binded to version 3.19 in web.config file.重新安装后,它仍然重定向到 3.19 版,因为它仍然绑定到 web.config 文件中的 3.19 版。 I did find all search for 3.19 with .我确实找到了 3.19 的所有搜索 file type and commented the setting which was referring 3.19.文件类型并注释了引用 3.19 的设置。 like one in web.config below就像下面的 web.config 中的一个

<!--<dependentAssembly>
        <assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.19.8.16603" newVersion="3.19.8.16603" />
      </dependentAssembly>-->

我通过切换到 PowerShell 5.1 解决了这个问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用 GetAzureADAppOnlyAuthenticatedContext 时无法加载文件或程序集“Microsoft.IdentityModel.Clients.ActiveDirectory” - Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory when calling GetAzureADAppOnlyAuthenticatedContext 无法加载文件或程序集“ Microsoft.IdentityModel.Clients.ActiveDirectory.Platform” - Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform' 缺少程序集引用Microsoft.IdentityModel.Clients.ActiveDirectory - Missing assembly reference Microsoft.IdentityModel.Clients.ActiveDirectory Microsoft.IdentityModel.Clients.ActiveDirectory v3.17.0 和 appid/appsecret - Microsoft.IdentityModel.Clients.ActiveDirectory v3.17.0 and appid/appsecret 对Microsoft.IdentityModel.Clients.ActiveDirectory 3.14.2的硬依赖性 - Hard dependency on Microsoft.IdentityModel.Clients.ActiveDirectory 3.14.2 将 Microsoft.IdentityModel.Clients.ActiveDirectory 升级到 5.2.9 后 AcquireTokenByAuthorizationCodeAsync 抛出错误 - AcquireTokenByAuthorizationCodeAsync throws error after upgrading Microsoft.IdentityModel.Clients.ActiveDirectory to 5.2.9 如何确保Microsoft.IdentityModel.Clients.ActiveDirectory库返回刷新令牌? - How do I make sure that a refresh token is returned by Microsoft.IdentityModel.Clients.ActiveDirectory library? 无法加载文件或程序集&#39;Microsoft.IdentityModel.Protocols.WsFederation, - Could not load file or assembly 'Microsoft.IdentityModel.Protocols.WsFederation, 无法加载文件或程序集 Microsoft.IdentityModel.Tokens 问题 - Could not load file or assembly Microsoft.IdentityModel.Tokens problem Microsoft.IdentityModel.Clients.ActiveDirectory.Platform不存在 - Microsoft.IdentityModel.Clients.ActiveDirectory.Platform not present
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM