2

I have a Dynamics CRM 2016 On-Prem plugin, it connects to an ASP.Net web api endpoint secured with Azure AD. Thus I use the library Microsoft.IdentityModel.Clients.ActiveDirectory

However when I deploy the plugin, it fails to run on Dynamics CRM with the error:

Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.2.7.0

Originally I thought this was available when installing Windows Identity Foundation (WIF) on the Dynamics CRM servers. Perhaps I have mis-understood this.

I next tried to use ILmerge. I already use ILmerge for Newtonsoft JSON assembly and that works fine, but as soon as I add Microsoft.IdentityModel.Clients.ActiveDirectory the plugin assembly no longer registers and it fails with:

Unable to publish the project: Exception: Microsoft.Crm.CrmException: GetAssemblyMetadata: expected mdtAssemblyRef or mdtAssembly

How can this issue be overcome?

Dean
  • 360
  • 1
  • 10
  • 27
  • Have you tried setting the copy local attribute to false for these IdentityModel assemblies? Have a look at this: https://community.dynamics.com/crm/b/nishantranaweblog/posts/microsoft-crm-crmexception-getassemblymetadata-expected-mdtassemblyref-or-mdtassembly-while-registering-plugin-assembly-in-dynamics-365 – Okan Konur May 22 '20 at 19:53
  • I did come across that link earlier, but if I set Copy Local to False, then the assembly is not copied to release folder and ILMerge cannot merge it. I was confused how this resolves the issue? I have also tried merging with ILMerge after the build has happened but outcome on Dynamics CRM is the same error message. – Dean May 22 '20 at 20:25
  • Normally you don't need to merge all the reference dlls if they are already installed on the target crm server (such as crm sdk libraries). We set these to false when merging to avoid any dll collision errors. – Okan Konur May 23 '20 at 21:04
  • 2
    Yep. I've got all the CRM references as copy local to false. The only ones with true are Newton JSON and Microsoft IdentityModel. There seems to be something about IdentityModel that Dynamics doesnt like. Looking around the internet some more, it looks like maybe Dynamics and ADAL is not a supported combination. – Dean May 24 '20 at 12:15
  • @Dean any solution? I'm having the same cryptic error... – Don Cheadle Jan 21 '22 at 23:28
  • @DonCheadle We never got around this :( Sorry. Instead we ended up calling Azure Functions instead which then called the Azure AD secured web app. – Dean Feb 02 '22 at 18:28
  • @Dean sounds good. My situation, might be a bit different, we ended up downgrading "RestSharp" Nuget package to a version that had 0 other dependencies. Then we could call the Azure Queue like we wanted... via HTTP/not using Azure SDK (had its own ILMerge nightmares) – Don Cheadle Feb 03 '22 at 21:41
  • 1
    @Dean a bottom line take-away for me regarding CRM Plugins and ILMerge.... is to count your lucky stars when ILMerge does work and try your hardest to include as few 3rd party DLL's as possible.... because ILMerge can be a real nightmare. Overall if I wrote a Plugin again that had to talk to other SDK's or Azure or anything complicated requiring more DLL's... I'd probably opt for the Service Endpoint approach totally. – Don Cheadle Feb 03 '22 at 23:51

0 Answers0