locked
Getting exception from Newtonsoft.Json in Dyn365 Online (8.2) RRS feed

  • Question

  • Hi,

    I'm developing an integration plugin that will call an external web service with data and have run into some issues.

    What I'm doing is making a JSON call to the API of the other system and I get a dynamic object back. The assembly is ilmerged withg Newtonsoft.Json and two dlls from the vendor of the target system. This works on a Dyn365 on premise while sandboxed but when I do it on an online 8.2 I get the following error:

    Unexpected exception from plug-in (Execute): AccountIntegration: System.TypeAccessException: Attempt by method 'DynamicClass.CallSite.Target(System.Runtime.CompilerServices.Closure, System.Runtime.CompilerServices.CallSite, System.Object, System.String)' to access type 'Newtonsoft.Json.Linq.JValue+JValueDynamicProxy' failed.

    if (client.CreateCall<string>("Api/Basic/Register/", project, out outstring, out fault, HttpVerbs.POST))
                {
                    pt.Trace("in call");
                    if (!string.IsNullOrEmpty(outstring))
                    {
                        dynamic outp = JArray.Parse(outstring);
                        pt.Trace("jarray.parce...");
                        if (outp.Count != 1)
                            returnObj = false;
                        else
                        {
                            pt.Trace("är det outp[0]?");
                            var objekt = outp[0];
                            if (objekt["ProjectTypeID"] != "ART")
                                error = "Wrong project type chosen";
                            else if (objekt["Customer"] != customerId)
                                error = "Wrong customer on project";
                            else
                                returnObj = true;
                        }
                        pt.Trace("efter allt koll");
    
    
                    }
                    else
                        error = "No project found";
                }

    It's the line "var objekt = outp[0];" that fails in the online version. Is this something that I can make work somehow? I am a bit surprised that something that works sandboxed on prem doesn't work online. (you can disregard the "pt.Trace" which is pure debug logging)

    (Can some moderator please move this to the development thred, I missed a click somewhere, sorry about that.)

    Thanks



    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se


    Sunday, February 26, 2017 8:20 PM

Answers

  • Try creating a class structure to match what you need to use and then deserialize into that instead of relying on Json,Linq dynamic paths if possible.  I would expect you to see the same error onprem or online in the sandbox. 

    .NET MVP / Microsoft Regional Director / http://blog.davidyack.com / http://crm.davidyack.com

    Tuesday, February 28, 2017 1:38 AM

All replies

  • Try creating a class structure to match what you need to use and then deserialize into that instead of relying on Json,Linq dynamic paths if possible.  I would expect you to see the same error onprem or online in the sandbox. 

    .NET MVP / Microsoft Regional Director / http://blog.davidyack.com / http://crm.davidyack.com

    Tuesday, February 28, 2017 1:38 AM
  • Thanks David! The solution was to use JArray instead of dynamic and JToken instead of var, then the Dyn365 online sandbox accepted it. The funny this is that it was working on an on-prem sandboxed 8.2, which was very much confusing.

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Tuesday, February 28, 2017 10:32 AM