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)

Call classes/method in DLL from X++

(0) ShareShare
ReportReport
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

*This post is locked for comments

I have the same question (0)
  • Iulian Cordobin Profile Picture
    8,201 on at

    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?

  • Lourense Profile Picture
    395 on at

    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
    8,201 on at

    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
    395 on at

    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

  • Verified answer
    Iulian Cordobin Profile Picture
    8,201 on at

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

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

  • Lourense Profile Picture
    395 on at

    Thank you Lulian, your help is much appreciated.

    It is working now.

    Lourens

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