Make use of DotNet Assemblies from DAX 4.0
As part of my AIF series of post, I thought that it would only be right to prepend and post about how to make native .Net assembly calls from DAX 4.0 X++ code.
This is a great addition to DAX, being able to take given .Net assemblies and create objects from classes, and make use of .Net code through native references and X++ code, rather than through COM.
With that said, let's jumpe right in and Talk about what it takes to make use of a .Net assembly from within Dynamics AX 4.0.
(1) First the given .Net assembly must be a signed one. Meaning that it must have a public token associated with it.
(2) Second the assembly needs to be installed into the GAC
Once you are for sure these two are done next is creating a reference within DAX. From the AOT you can go to close to the bottom and you will see references. From there right click and add a reference. The reference form will pop up and you will have to click on the browse button and select your .DLL .Net Assembly.
Once the reference is made, then you can move on to creating code that makes use of the given .Net assembly. I say start with a new job. ONce you have the new job created, add code that looks similar to this:
static void DotNetIntegration(Args _args)
{
DotNetAssembly.DNClass DNC;
str s;
CLRObject clrDNC;
;
clrDNC = new DotNetAssembly.DNClass();
DNC = clrDNC;
s = DNC.DNMethod("Test");
info(strfmt("%1",s));
}
Now to speak a little bit about this code. The first line DotNetAssembly.DNClass DNC; Is a declaration that makes use of the Referenced Assembly, and one of it's exposed classes. Next we have a standard str s declaration, and then what makes the interaction possible, the CLRObject declaration.
From there we move on to the execution of code, which shows the following line first: clrDNC = new DotNetAssembly.DNClass(); This line is very important, in that it creates a new instance of the clrDNC CLRObject class. What you have to realize at this point is that all .Net Assembly Classes are CLRObjects, and therefore must be created as so. Notice the next line is we set the newly created clrDNC object and make the DNC object equal to that. By doing this we get the look ahead ability to view the methods within the .Net assembly, for example the line of code: s = DNC.DNMethod("Test");
So you can take any .Net assembly, make sure the assembly is signed and installed into the GAC, and then make use of the CLRObjects you can interact with Dot Net with native X++ calls, without having to make use of COM.
Check back soon for more!
Find a job at: www.DynamicsAXJobs.com
This is a great addition to DAX, being able to take given .Net assemblies and create objects from classes, and make use of .Net code through native references and X++ code, rather than through COM.
With that said, let's jumpe right in and Talk about what it takes to make use of a .Net assembly from within Dynamics AX 4.0.
(1) First the given .Net assembly must be a signed one. Meaning that it must have a public token associated with it.
(2) Second the assembly needs to be installed into the GAC
Once you are for sure these two are done next is creating a reference within DAX. From the AOT you can go to close to the bottom and you will see references. From there right click and add a reference. The reference form will pop up and you will have to click on the browse button and select your .DLL .Net Assembly.
Once the reference is made, then you can move on to creating code that makes use of the given .Net assembly. I say start with a new job. ONce you have the new job created, add code that looks similar to this:
static void DotNetIntegration(Args _args)
{
DotNetAssembly.DNClass DNC;
str s;
CLRObject clrDNC;
;
clrDNC = new DotNetAssembly.DNClass();
DNC = clrDNC;
s = DNC.DNMethod("Test");
info(strfmt("%1",s));
}
Now to speak a little bit about this code. The first line DotNetAssembly.DNClass DNC; Is a declaration that makes use of the Referenced Assembly, and one of it's exposed classes. Next we have a standard str s declaration, and then what makes the interaction possible, the CLRObject declaration.
From there we move on to the execution of code, which shows the following line first: clrDNC = new DotNetAssembly.DNClass(); This line is very important, in that it creates a new instance of the clrDNC CLRObject class. What you have to realize at this point is that all .Net Assembly Classes are CLRObjects, and therefore must be created as so. Notice the next line is we set the newly created clrDNC object and make the DNC object equal to that. By doing this we get the look ahead ability to view the methods within the .Net assembly, for example the line of code: s = DNC.DNMethod("Test");
So you can take any .Net assembly, make sure the assembly is signed and installed into the GAC, and then make use of the CLRObjects you can interact with Dot Net with native X++ calls, without having to make use of COM.
Check back soon for more!
Find a job at: www.DynamicsAXJobs.com
3 Comments:
Sorry for the late reply. Anyway, for this to work in a 3-tier environment, the Assembly needs to be installed into the GAC (windows\assembly) on the given AOS.
Then from there, you will see your DotNet Assembly appear in the GRID for selection. Create the reference in the AOT using what is being displayed from the Grid. In doing so, you now have made it to where the DotNet Assembly will be executed from the AOS, instead of a client reference.
I hope this helps!
Maybe I'm wrong but this integration doesn't allow use properties so many maaany classess in unusable, or we have to write wrappert around property to make it method.
Or I'm wrong ?
krzak,
This is correct you need to create an adatper in order to enable the use of some .Net functions.
For example to fill in or get properties, then you need to create wrapper get & set methods for doing this.
In the next release of DAX 5.0, this will not have to take place.
-Brandon
Post a Comment
<< Home