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

时间:2019-01-03 20:55:46

标签: dynamics-crm microsoft-dynamics dynamics-crm-online

我正在开发使用ADAL nuget软件包的插件。由于缺少Microsoft.IdentityModel.Clients.ActiveDirectory dll,我的插件程序集在执行时引发异常。程序集正在引用并在合并的dll中正确合并,这就是我在ILSpy工具中看到的内容:

enter image description here

这是我的插件程序集中的引用列表:enter image description here

有什么办法解决此问题吗?

在尝试使用ILMerge和ILRepack合并多个dll的工具后,我遇到了相同的问题。我如何找出我认为是错误根源的Clients.ActiveDirectory依赖项?

此插件已部署到CRM在线实例中,因此我们无法像在本地一样将dll添加到GAC中。

这是我执行使用ADAL nuget软件包的插件时从插件注册工具中看到的确切错误消息:

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>

3 个答案:

答案 0 :(得分:1)

根据this article,不支持在插件中使用ILMerge。

您是否要使用ADAL访问CRM或另一个Azure系统?如果要访问CRM,则可以使用本机IOrganizationService。

如果您要定位另一个系统,则可能要考虑使用Azure aware plugin来逃离沙箱并在CRM外部运行逻辑。

答案 1 :(得分:0)

  1. 您可以检查是否从GAC添加了此引用。
    如果是,那么您可能需要将jt设置为复制到输出目录。 您可以检查文件是否在执行目录中。

  2. 另一个原因可能是您有多个引用此adal的项目。每个都引用不同的版本。 它们都设置为复制到输出目录。但是最终的构建输出没有插件所需的版本。

答案 2 :(得分:0)

您必须将所有必需的dll合并到单个插件dll中,然后进行注册。您可以使用ILMERGE来做到这一点。

Read more

即使您可以使用构建后的Powershell命令脚本来自动执行此操作。