Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

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

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
    Naveen Ganeshe 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
    Thomas David Dayman 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/

  • 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
    fariba 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
    Guido Preite 54,081 Super User 2024 Season 1 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;
    }

  • 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
    Guido Preite 54,081 Super User 2024 Season 1 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?

  • 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
    Guido Preite 54,081 Super User 2024 Season 1 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans