web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
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.

I have the same question (0)
  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

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

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

  • Dheeraj Raghav Profile Picture
    on at

    Sorry, this approach is not working.

  • Guido Preite Profile Picture
    54,086 Moderator on at

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

  • Dheeraj Raghav Profile Picture
    on at

    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.

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    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;
    }

  • Verified answer
    fariba Profile Picture
    40 on at

    Hello

    please uninstall current ILMerge package and try to install using command

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

  • Dheeraj Raghav Profile Picture
    on at

    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>

  • Thomas David Dayman Profile Picture
    11,323 on at

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

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    Hello Dheeraj,

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

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 52

#2
Manoj - ManoVerse Profile Picture

Manoj - ManoVerse 43 Super User 2026 Season 1

#3
Ayesha Wajahat Profile Picture

Ayesha Wajahat 14

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans