Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

plugin using newtonsoft.json

Posted on by 386

Could you please help with the following issue:

<Message>Unexpected exception from plug-in (Execute): PluginXXXXCreate: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.</Message>

I need to use Newtonsoft.json from Dynamics plugin

I have installed Json.Net using NuGet, these are the settings below. 

packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net452" />
</packages>

This is the reference Newtonsoft.json dll added to the Visual Studio project

version 10.0.0.0

XXXXX\Visual Studio Solution\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll

XXX.csprj

<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>

*This post is locked for comments

  • slx Profile Picture
    slx 386 on at
    RE: plugin using newtonsoft.json

    I would like to avoid using newtonsoft.json but I can't get data deserialized

    this is the odata json

    {

     "@odata.context": "http://test_link/$metadata#docs(Id,Code,Version)",

     "value": [

       {

         "@search.score": 1,

         "Id": "3",

         "Code": 3,

         "Version": 1,

         },

    {message2},

    {message3},

    }

    and these my c# classes

     public class OData

       {

           [JsonProperty("odata.metadata")]

           public string Metadata { get; set; }

           public List<Resp> Value { get; set; }

       }

       public class Resp

       {

           public Resp() { }

           public string Id { get; set; }

           public string Code { get; set; }

           public string Version { get; set; }

    }

  • slx Profile Picture
    slx 386 on at
    RE: plugin using newtonsoft.json

    Thank you for reply, is this raising a security issue? (compiling external dll inside plugin sandbox env) ?

    Also , could you please assist with the change of the file ? this is csprj

     <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

     <!-- To modify your build process, add your task inside one of the targets below and uncomment it.

          Other similar extension points exist, see Microsoft.Common.targets.

     <Target Name="BeforeBuild">

     </Target>

     <Target Name="AfterBuild">

     </Target>

     -->

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: plugin using newtonsoft.json

    if it is just to serialize a json to a data contract, you could use

    Complaint jsonData = new Complaint();
    byte[] result = Encoding.UTF8.GetBytes(data);
                        using (var jsonReader = JsonReaderWriterFactory.CreateJsonReader(result, XmlDictionaryReaderQuotas.Max))
                        {
                            var outputSerialiser = new DataContractJsonSerializer(jsonData.GetType());
                            jsonData = outputSerialiser.ReadObject(jsonReader) as Complaint;
                        }


    -- It saves you from ILMerging Newtonsoft.json.

    you have to add

    using System.Runtime.Serialization.Json;

    Regards,

    Jithesh

  • Suggested answer
    Gee Bee Profile Picture
    Gee Bee 11,397 on at
    RE: plugin using newtonsoft.json

    You need to use ILMerge to include external dll or another project assembly to your plugin

    Please refer

    gonzaloruizcrm.blogspot.co.uk/.../including-reference-assemblies-in.html

  • slx Profile Picture
    slx 386 on at
    RE: plugin using newtonsoft.json

    and these are installed packages

    PM> Get-Package

    Id                             Version              Description/Release Notes                                                

    --                             -------              -------------------------                                                

    Microsoft.CSharp               4.3.0                Provides support for compilation and code generation, including dynamic...

    Newtonsoft.Json                10.0.2               Json.NET is a popular high-performance JSON framework for .NET            

    NuGetPowerTools                0.29                 Powershell goodies that make working with nuget even easier!    

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