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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Newtonsoft Json include in crm plugin

(0) ShareShare
ReportReport
Posted on by

HI,

I tried including NewtonSoft  Json dll in my crm plugin to parse Json via OData web service for purpose of update. When I am trying to deploy my plugin, it seems NewtonSoft dll does not get included. I tried many things Like ILMerge, using System.Json and all other ideas but non seems working. Does anyone has successfully achieved what I am trying to do. If yes, please help.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    Check below article -

    www.develop1.net/.../ILMergeNotSupported

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    You are on CRM 2015 On-Prem, If you use Newtonsoft, you have two options to get this working

    01. You can GAC the Newtonsoft DLL to the CRM server using the GAC util but i would not recommend this as its adding extra step to the deployment and if you have to deploy to the different server, you will have to follow the step again.

    02. The preferred option is to use the ILMerge, please see below as to how you can get this working

    a. Make sure you add the following nuget to the project

    [View:https://www.nuget.org/packages/MSBuild.ILMerge.Task/:750:50]

    ScreenClip-_5B00_492_5D00_.png

    b. Make sure you plugin assembly is signed

    ScreenClip-_5B00_492_5D00_.png

    d. Make sure NewtonSoft DLL is copied to the output folder so that the ILMerge task can merge it

    ScreenClip-_5B00_491_5D00_.png

    If you use tools like dotpeak, you can drop the compiled plugin dll to see if newtonsoft is included in the plugin dll

    https://www.jetbrains.com/decompiler/

  • Suggested answer
    Mr. M Profile Picture
    5 on at

    You can choose one option below (I ran it in v9.1):

    1. For On premises:
    - Copy "...\Dynamics 365\Server\bin\Newtonsoft.Json.dll" to "...\Dynamics 365\Server\bin\assembly\Newtonsoft.Json.dll".
    - Reference the dll to your project and write code as usual.
    - Register your plugin with Isolation Mode "None".  Newtonsoft.Json will work fine.
    (Temporary, I don't know location of Isolation Mode Sandbox in hard disk, you can try).
    2. For Online + On premises:
    - You need to flat your JSON string before processing, if you use nested objects, they will be parse as C# raw object and you cannot access their attributes. 
    - Using System.Runtime.Serialization.Json.DataContractJsonSerializer with setting DataContractJsonSerializerSettings.UseSimpleDictionaryFormat = true and typeof Dictionary<string, object>.
    - Use the serializer to read the object from JSON then you can access & get value by key.
    var jsonData = Encoding.UTF8.GetBytes(@"{""name"":""Name 1""}");
    var serializerOptions = new DataContractJsonSerializerSettings()
    {
    UseSimpleDictionaryFormat = true
    };
    var serializer = new DataContractJsonSerializer(typeof(Dictionary<string, object>), serializerOptions);
    var data = serializer.ReadObject(new MemoryStream(jsonData)) as Dictionary<string, object>;
    You also can declare data contract class to use with DataContractJsonSerializer, but it seem this way costs more time to declare contract.
    Hope this will help you.
    Caution: using System.Web.Script.Serialization.JavaScriptSerializer from System.Web.Extensions.dll will cause your execution failed.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans