Agile Tortoise

Greg Pierce’s blog

« Slicehost: installing imagemagick      Rails: flatten your content model with single-table inheritance and alias_attribute »

Dynamics AX: Making .NET calls from inside AX

In a typical fashion, Microsoft spent a lot of effort integrating a variety of it's new technologies in Dynamic AX 4 (nee Axapta). Often these additions are of questionable benefit to the end-user/customer -- but, the ability to make direct calls to the .NET/CLR from AX's built in X++ language is pretty handy for the developer.

The process is pretty simple. Add a reference in the AOT to your CLR assembly -- or a reference to .NET's "System" namespace is already available. Assert permissions to access the bridge (just a wrapper for Window auth), then make your calls.

You declare your variables in their native CLR types, and use the methods of the CLRInterop class in AX to caste to AX data types. Here's an example to build an AX container of file names in a directory, something trivial in .NET that's actually a bit of a pain with AX's limited built in file/directory methods.

CODE:
  1. void buildFileList( str _folder )
  2. {
  3.     InteropPermission perm = new InteropPermission( InteropKind::ClrInterop );
  4.     container fList;
  5.     System.Array dirList;
  6.     int ix;
  7.     ;
  8.  
  9.     perm.assert();
  10.  
  11.     dirList = System.IO.Directory::GetFiles( _folder );
  12.     for( ix=0; ix <ClrInterop::getAnyTypeForObject( dirList.get_Length() ); ix++ )
  13.     {
  14.         fList = conins( fList, conlen(fList)+1, ClrInterop::getAnyTypeForObject( dirList.GetValue(ix) ) );
  15.     }
  16.     return fList;
  17. }

Monday, April 2nd, 2007 at 6:35 am and is filed under .NET, Dynamics AX. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “Dynamics AX: Making .NET calls from inside AX”

  1. Hendra Says:
    March 19th, 2008 at 12:08 am

    Dear,
    I need X++ book.
    Do you can help me?
    Rgds,
    Hendra

  2. Joel Says:
    August 17th, 2008 at 10:02 am

    Is there any way to place .Net Usercontrol on a form inside AX??

Leave a Reply