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 AX (Archived)

Using Newtonsoft.JSon in a class that runs on server

(0) ShareShare
ReportReport
Posted on by 10

Hello!

I am trying use Newtonsoft.Json and the JsonReader class taken from axgrind.azurewebsites.net/.../AX-2009-and-JSON-Parsing to process a json string. I copied the Newtonsoft.Json.dll into C:\Program Files (x86)\Microsoft Dynamics AX\50\Client\Bin\, and added a reference in AOT to this DLL. To be able to run my class on server side I also copied the DLL in C:\Program Files\Microsoft Dynamics AX\50\Server\ApplName\Bin\ on AOS server too. Now my class runs fine if its RunOn is set to Client, but fails with Server or Called from settings with the following error:

Request for the permission of type 'InteropPermission' failed.
(S)\Classes\InteropPermission\demand
(S)\Classes\CLRInterop\staticInvoke
(S)\Classes\JsonReader\loadJson - line 3
(S)\Classes\JsonReader\parseJson - line 6
(S)\Classes\XMI_JSonTest\run - line 21
(C)\Classes\XMI_JSonTest\main - line 7

The JSonReader class' RunOn is set to CalledFrom.

The code that fails:

void run()
{
JsonReader reader;
Newtonsoft.Json.Linq.JObject token;
str json, sKey, sName;
int i;
;

json = '{"key":86934,' +
'"name":"Data",' +
'"folders":[{"key":90296,"name":"Folder 1"},' +
'{"key":90294,"name":"Folder 2"},' +
'{"key":90295,"name":"Folder 3"},' +
'{"key":90292,"name":"Folder 4"},' +
'{"key":90293,"name":"Folder 5"},' +
'{"key":90297,"name":"Folder 6"}' +
']' +
'}';

new InteropPermission(InteropKind::ClrInterop);
reader = jsonreader::parseJson( json );
...
CodeAccessPermission::revertAssert();
}

The code stops executing at line
reader = jsonreader::parseJson( json );

public static JsonReader parseJson(str _json)
{
JsonReader reader = new JsonReader();
;

reader.loadJson(_json);
return reader;
}

public void loadJson(str _json)
{
jObject = Newtonsoft.Json.Linq.JObject::Parse(_json);
}

What am I doing wrong?

Thank you!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Make sure the library you are using is not client bound by only being compiled for x86 (32-bit architecture), since the AX AOS is a 64-bit process.

    [View:https://blogs.msdn.microsoft.com/emeadaxsupport/2009/10/19/using-the-dllfunction-kernel-class-on-a-64bit-dynamics-ax-2009-aos/:750:50]

    [View:https://philippsen.wordpress.com/tag/clrobject-could-not-be-created/:750:50]

  • Suggested answer
    Daniel Weichsel Profile Picture
    on at

    Change this line:

    new InteropPermission(InteropKind::ClrInterop);

    To:

    new InteropPermission(InteropKind::ClrInterop).assert();

    You are constructing the InteropPermission but not asserting it.

  • Barni Profile Picture
    10 on at

    Thank you!

    Sometimes I get stucked with such mistakes, and I need someone to see my code, because I just can't find them, nomatter how many times I check each line.

    Thanks again!

  • Avinesh Chand Profile Picture
    120 on at

    Hi, were you able to make it run on server?

    I am getting same error.

    Thanks

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi, 

    this question has a verified answer (check the message(s) with a green symbol next to them. It means that the original issue was resolved and you can check the verified messages and solve your problem. If it's not the same issue (and not resolved with the verified answer) , you can post a new question. 

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 AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans