Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory' in CRM Plugin

牧云@^-^@ 提交于 2021-01-29 07:44:23

问题


I am developing a plugin that uses ADAL nuget package. My plugin assembly throws an exception when I execute due to missing Microsoft.IdentityModel.Clients.ActiveDirectory dll. The assembly is referencing and merged properly in the merged dll and this is what I see in ILSpy tool:

Here is the list of references in my plugin assembly:

Any ideas how to fix this issue?

After i tried multiple tools to merge my dlls using ILMerge and ILRepack i am facing the same issue. How can i find out Clients.ActiveDirectory dependencies which i think it is the root cause of the error?

This plugin is deployed into a CRM online instance, so I can't add dlls into GAC as we do on-premise.

Here is the exact error message I see from the Plugin Registration tool when I execute my plugin that uses ADAL nuget package:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: **Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=4.4.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencie**s. The system cannot find the file specified.
Detail: <OrganizationServiceFault xmlns="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <ActivityId>00000000-0000-0000-0000-000000000000</ActivityId>
  <ErrorCode>-2147220970</ErrorCode>
  <ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    <KeyValuePairOfstringanyType>
      <a:key>CallStack</a:key>
      <a:value i:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema">   at Microsoft.Dynamics.PerceptionAnalytics.Plugins.ProvisionFloorPlan.&lt;Execute&gt;d__0.MoveNext()
   at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine](TStateMachine&amp; stateMachine)
   at Microsoft.Dynamics.PerceptionAnalytics.Plugins.ProvisionFloorPlan.Execute(IServiceProvider serviceProvider)
   at PluginProfiler.Library.PluginAppDomainProxy.ExecuteCore(Stopwatch watch, ProfilerExecutionReport report, Object instance, Object executionParameter)
   at PluginProfiler.Library.AppDomainProxy.Execute(ProfilerExecutionConfiguration configuration, ProfilerExecutionReport report)</a:value>
    </KeyValuePairOfstringanyType>
  </ErrorDetails>
  <Message>Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=4.4.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.</Message>
  <Timestamp>2019-01-03T18:30:29.4049324Z</Timestamp>
  <ExceptionRetriable>false</ExceptionRetriable>
  <ExceptionSource i:nil="true" />
  <InnerFault i:nil="true" />
  <OriginalException i:nil="true" />
  <TraceText i:nil="true" />
</OrganizationServiceFault>

回答1:


As per this article, using ILMerge in plugins is unsupported.

Are you trying to use ADAL to access CRM, or another Azure system? If you're accessing CRM, you can use the native IOrganizationService.

If you're targeting another system, you may want to consider using an Azure aware plugin to escape the sandbox and run your logic outside of CRM.




回答2:


You have to merge all the necessary dlls into single plugin dll and then register it. You can use ILMERGE to do it.

Read more

Even you can have a post build Powershell commands script to do it automatically.




回答3:


  1. you can check if you added this reference from GAC.
    If yes, then you may want to set jt to copy to ouput directory. You can check if the file is existing in the execution directory.

  2. Another reason can be that you have multiple projects referring to this adal. Each referring to different version. Both of them set to copy to output directory. But the final build output does not have the version expected by the plug-in.



来源:https://stackoverflow.com/questions/54029679/could-not-load-file-or-assembly-microsoft-identitymodel-clients-activedirectory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!