Tuesday, September 15, 2020

D365 Plugin : Merge External Assemblies using IL Merge

Due to the SANDBOX isolation mode in all D365 CRM online versions, registering an external assembly will give an error.

This error will occur when we trigger an Event to which our Plugin using external DLL is registered.

Scenario-

From Plugin, we need to call an API Endpoint, send request and receive response against it. 

Before sending the request parameter we need to serialize the class object and after receiving response deserialize the response object, for which we used Newtonsoft.json 

As Newtonsoft.json is an external assembly we need to merge it with plugin assembly before registering it in Plugin Registration Tool.

Refer –  Call Azure Function from Dynamics 365 via Plugin – Part 5.1

Follow the below steps to merge the same.

1. Open Plugin in Visual Studio and add an external assembly.
2. Open NuGet Package Manager.
3. Search ILMerge and Install it.

Note: Internal Assemblies need to be excluded from merge to keep size of assembly less, like-

Microsoft.Xrm.Sdk.dll

Microsoft.Crm.Sdk.Proxy.dll

Microsoft.IdentityModel.dll

4. Go the properties of such assemblies and set Copy Local to False.
5. Rebuild the solution.

Below is the merged Assembly.

Note: In case when we will not exclude assemblies like Microsoft.Xrm.Sdk.dll from merging, the merged assembly size will be way more than actual-

Whoooohaa! We did it.

Happy Learning, LET'S SHARE !

No comments:

Post a Comment

Popular Posts