Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Call classes/method in DLL from X++

Posted on by 395

Hi

I have a DLL (written in C#) with several methods  that I need to call from X++. I have created a reference in the AOT to the DLL but when I try to use it in the X++Class. Intellisense does not have the classes or methods available an options.

No matter what I try, X++ does not recognise the classes or methods.  Is there something other than setting the references that I need to do?

Regards

Lourens

  • Lourense Profile Picture
    Lourense 395 on at
    RE: Call classes/method in DLL from X++

    Thank you Lulian, your help is much appreciated.

    It is working now.

    Lourens

  • Verified answer
    Iulian Cordobin Profile Picture
    Iulian Cordobin 8,201 on at
    RE: Call classes/method in DLL from X++

    You've declared your methods static, so the right call would be

    x =  Calcs.Operations::add(a, b);

  • Lourense Profile Picture
    Lourense 395 on at
    RE: Call classes/method in DLL from X++

    Hi Lulian

    I have done what you suggested and it compiled without a problem. It also showed up in Intellisense.

    I then added a method Main with the following code:

    private void main()

    {

       int x;

       x=test.add(1,2);

    }

    I then get an error: The method add has not been declared.

    My only remaining problem is that I can not call the method "add".

    Any suggestions?

    Lourens

  • Iulian Cordobin Profile Picture
    Iulian Cordobin 8,201 on at
    RE: Call classes/method in DLL from X++

    Yes, it's much clearer, however, I am not sure why it's not working. All you did is fine.

    Can I suggest, just close again the AX client completely (both the client and development workspaces), and after reopening it, just compile the class in the AOT tree, without actually opening the class's code.

  • Lourense Profile Picture
    Lourense 395 on at
    RE: Call classes/method in DLL from X++

    Thank you for getting back to me Lulian

    The location of the DLL is in "C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin"

    I have restarted the Client

    I do not see in Intellisense and the code does not compile

    I used >NET Framework 4.0.30319

    using System;

    namespace Calcs

    {

       public class Operations

       {

           public static int add(int a, int b)

           {

               return a + b;

           }

           public static int substract(int a, int b)

           {

               return a - b;

           }

           public static int multiply(int a, int b)

           {

               return a * b;

           }

       }

    }

    I compiled it to C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\calcs.dll

    from the command line using

    C:\Windows\Microsoft.net\Framework\v4.0.30319\csc.exe /target:library /out:calcs.dll calcs.cs

    I then created a reference in the AOT to C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\calcs.dll

    I restarted the AOS and then in X++ I tried:

    class aaTest

    {

       Calcs.Operations test;

    }

    Calcs.Operations is then underlined and it will not compile.

    I hope the above makes it a bit more clear.

    Lourens

  • Iulian Cordobin Profile Picture
    Iulian Cordobin 8,201 on at
    RE: Call classes/method in DLL from X++

    What is the dll location (GAC, client's Bin folder, other location on hard drive)?

    Have you restarted the client after adding the reference?

    Are you declaring your variables using the fully qualified namespace names?

    You have a problem with the only the Intellisense or is the code not compiling?

    What .Net framework was used to build the dll?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,835 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,526 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans