Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to use IL Merger to merge Newtonsoft.Json.dll with plugin DLL?

(0) ShareShare
ReportReport
Posted on by

Hello,

I am calling a third-party API inside my plugin which is registered on an entity's create-event. Now I want to parse the API JSON result in this plugin. To parse it, I am using Newtosoft.Json.dll. Which is not parsing this JSON. I also tried to merge Newtosoft.Json.dll with my plugin DLL using IL merger, but it gives an error while I register this plugin using the plugin registration tool.

I tried the same Newtosoft.Json.dll in a console application. There it is working fine in my system.

Please help me to resolve this issue. Either tell me another way to parse API JSON results or share the right way to merge these DDLs to parse API JSON results.

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,393 User Group Leader on at
    RE: How to use IL Merger to merge Newtonsoft.Json.dll with plugin DLL?

    Hello Dheeraj,

    You can follow this link: vishalgrade.com/.../

  • Thomas David Dayman Profile Picture
    11,323 on at
    RE: How to use IL Merger to merge Newtonsoft.Json.dll with plugin DLL?

    I use ILMerge-GUI if I need to merge dlls - archive.codeplex.com/

  • Dheeraj Raghav Profile Picture
    on at
    RE: How to use IL Merger to merge Newtonsoft.Json.dll with plugin DLL?

    I followed your instructions. But still, it is not working.

    While I am debugging the plugin code it is showing the below mentioned error:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad36****]]: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6****' or one of its dependencies. The system cannot find the file specified.
    Detail: <OrganizationServiceFault xmlns="">schemas.microsoft.com/.../Contracts" xmlns:i="">www.w3.org/.../XMLSchema-instance">
    <ActivityId>00000000-0000-0000-0000-000000000000</ActivityId>
    <ErrorCode>-2147220970</ErrorCode>
    <ErrorDetails xmlns:a="">schemas.datacontract.org/.../System.Collections.Generic">
    <KeyValuePairOfstringanyType>
    <a:key>CallStack</a:key>
    <a:value i:type="b:string" xmlns:b="">www.w3.org/.../XMLSchema"> at SMSTransactionalRequest.SMSTransactionalRequest.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 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6****' or one of its dependencies. The system cannot find the file specified.</Message>
    <Timestamp>2021-07-19T05:18:10.2455869Z</Timestamp>
    <ExceptionRetriable>false</ExceptionRetriable>
    <ExceptionSource i:nil="true" />
    <InnerFault i:nil="true" />
    <OriginalException i:nil="true" />
    <TraceText i:nil="true" />
    </OrganizationServiceFault>

  • Verified answer
    fariba Profile Picture
    40 on at
    RE: How to use IL Merger to merge Newtonsoft.Json.dll with plugin DLL?

    Hello

    please uninstall current ILMerge package and try to install using command

    Reference for more clarification:www.inogic.com/.../

  • Suggested answer
    Guido Preite Profile Picture
    54,077 Moderator on at
    RE: How to use IL Merger to merge Newtonsoft.Json.dll with plugin DLL?

    I just checked and in my case it works, I don't know where you copied that deserialization code, but this is the one that works for me:

    // Deserialize to Object
    using (MemoryStream memoryStream = new MemoryStream(Encoding.Default.GetBytes(responseString)))
    {
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Welcome));
        Welcome serializedObject = serializer.ReadObject(memoryStream) as Welcome;
    }

  • Dheeraj Raghav Profile Picture
    on at
    RE: How to use IL Merger to merge Newtonsoft.Json.dll with plugin DLL?

    There is no error. But while I write code like mentioned below:

    using (MemoryStream DeSerializememoryStream = new MemoryStream())

                                           {

                                               //Json String that we get from web api

                                               string ResponseString = result;

                                               DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Welcome));

                                               //user stream writer to write JSON string data to memory stream

                                               StreamWriter writer = new StreamWriter(DeSerializememoryStream);

                                               writer.Write(jsonString);

                                               writer.Flush();

                                               DeSerializememoryStream.Position = 0;

                                               //get the Desrialized data in object of type Welcome

                                               Welcome SerializedObject = (Welcome)serializer.ReadObject(DeSerializememoryStream);

                                           }

    Then no value coming in the object SerializedObject. It is blank.

  • Guido Preite Profile Picture
    54,077 Moderator on at
    RE: How to use IL Merger to merge Newtonsoft.Json.dll with plugin DLL?

    so what doesn't work? which error you are getting now?

  • Dheeraj Raghav Profile Picture
    on at
    RE: How to use IL Merger to merge Newtonsoft.Json.dll with plugin DLL?

    Sorry, this approach is not working.

  • Suggested answer
    Guido Preite Profile Picture
    54,077 Moderator on at
    RE: How to use IL Merger to merge Newtonsoft.Json.dll with plugin DLL?

    try to avoid using newtonsoft inside a plugin, you can use DataContractJsonSerializer

    here a sample www.crmanswers.net/.../json-and-crm-sandbox-plugins.html

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

#3
Sahra Profile Picture

Sahra 43

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans