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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer Service forum

Getting error when trying to consume a service in plugin.

(0) ShareShare
ReportReport
Posted on by

Hi All,

In visual studio 2012, i have added all libraries and added NewtonJsoft also but i get following error which debugging it.

'

<Message>Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.</Message>
Microsoft.NETCore.Platforms'

How ever my code runs perfectly in Console?

Is there any work around to avoid this error?

'

Categories:
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    This is becasue you have added a reference or nuget package for the assembly "Newtonsoft.Json". For CRM Online, plugins cannot referenced any external assemblies. You need to do the serialization manually using the DataContractJsonSerializer.

    Alternatively, you need to merge your plugin.

    Refer these:

    www.inogic.com/.../working-with-json-objects-in-dynamics-crm-plugins

    www.thrives.be/.../external-assemblies-dynamics-crm-plugins-ilmerge

    Hope this helps.

  • Community Member Profile Picture
    on at

    Thanks Ravi. Let me try that.

  • Community Member Profile Picture
    on at

    Hi Ravi,

    I tried,

    my code:

    namespace HttpClientSample

    {

       [DataContract]

       public class Student

       {

           [DataMember]

           public string Ssid { get; set;  }

           [DataMember]

           public string Verbatim { get; set; }

           [DataMember]

           public string Category { get; set; }

           [DataMember]

           public string Sub_Category { get; set; }

       }

      /* public class Verbatim

       {

           public string Verb { get; set; }

       }*/

       class Program

       {

           static HttpClient client = new HttpClient();

           string secretkey = string.Empty;

           string userName = "admin";

           string passWord = "admin";  

           static void Main(string[] args)

           {

               IOrganizationService service = GetOrganization();

               Entity ensmart = new Entity("ics_smartfeedbacks");

               string fetchxml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +

    "  <entity name='ics_smartfeedbacks'>" +

    "    <attribute name='ics_smartfeedbacksid' />" +

    "    <attribute name='ics_name' />" +

    "    <attribute name='createdon' />" +

    "    <attribute name='new_verbatim' />" +

    "    <attribute name='ics_feedbackcodes' />" +

    "    <attribute name='ics_feedbacksubcode' />" +

    "    <attribute name='ics_ssid' />" +

    "    <order attribute='ics_name' descending='false' />" +

    "    <filter type='and'>" +

    "      <filter type='and'>" +

    "        <condition attribute='new_verbatim' operator='not-null' />" +

    "        <filter type='or'>" +

    "          <condition attribute='new_isverbatimupdated' operator='eq' value='0' />" +

    "          <condition attribute='new_isverbatimupdated' operator='null' />" +

    "        </filter>" +

    "      </filter>" +

    "    </filter>" +

    "  </entity>" +

    "</fetch>";

                   using (MemoryStream SerializememoryStream = new MemoryStream())

                   {

                       //create a sample data of type Student Class add details

                       Student NewStudent = new Student();

                       NewStudent.Ssid = "Shahzeb";

                       NewStudent.Verbatim = "testing";

                       //initialize DataContractJsonSerializer object and pass Student class type to it

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

                       //write newly created object(NewStudent) into memory stream

                       serializer.WriteObject(SerializememoryStream, NewStudent);

                       //use stream reader to read serialized data from memory stream

                       StreamReader sr = new StreamReader(SerializememoryStream);

                       Console.WriteLine(serializer);

                       //get JSON data serialized in string format in string variable

                       string Serializedresult = sr.ReadLine();                      //i'm getting null here, its blank. is there any mistake.

                   }

  • Community Member Profile Picture
    on at

    I solved it sir. But my registration tools stops working when it reaches the GetRequestStream()

    "

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

             request.Method = "POST";

             request.ContentType = "application/x-www-form-urlencoded";

             request.Headers.Add("Authorization: " + "Bearer" + " " + KEY);

             request.ContentLength = data.Length;

             Stream stream = request.GetRequestStream();    // error

             {

                 stream.Write(data, 0, data.Length);

             }

             var response = (HttpWebResponse)request.GetResponse();

             var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

             }

    "

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Are you still getting error? If not and the issue is resolved. Please close the thread by marking the suggestion as helpful.

  • Community Member Profile Picture
    on at

    yes ravi, my plugin registration tool stops working and close down when it reaches the GetRequest Stream function.

    Please guide.

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Could you please share more details what do you mean by " plugin registration tool stops working and close down when it reaches the GetRequest Stream", plugin registration tool is used to register the plugin. Do you meant debugging the plugin?

  • Community Member Profile Picture
    on at

    I mean ravi, as i'm consuming third party service in my plugin and sending POST request, everything works well in console.

    But when my debugger reaches the GetRequuestStream function then my plugin registration tool crashes and my code stopped right there.

    MY CODE

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = "POST";

            request.ContentType = "application/x-www-form-urlencoded";

            request.Headers.Add("Authorization: " + "Bearer" + " " + KEY);

            request.ContentLength = data.Length;

            Stream stream = request.GetRequestStream();    // error

            {

                stream.Write(data, 0, data.Length);

            }

            var response = (HttpWebResponse)request.GetResponse();

            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

            }

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    It is possible that the GetResponseStream method is taking time to retrive the response hence the tool becomes unresponsive. Did you check if your plugin works normally (i.e. without debugging)?

  • Community Member Profile Picture
    on at

    Yes, it do. But if i take of GetRequestStream function.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Customer Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans