Wednesday, January 9, 2013

AX X++ compile and compile forward explanations



When there is a stack trace error or a code promotion, people often ask about the need to compile and compile forward. I think its important for people to realize the purpose for those two processes and how to do them. Note: Synchronizing is different than compiling. I can write a post on that if people are interested.

In AX, there are two types of compilations: Compiling and compiling forward. You can compile objects individually, as a group, or with the entire application. There is also an option to 'compile into CIL' in AX 2012. I'm not getting into this option as a clean compile is needed for that step. Compiling is essentially taking the X++ code and 'packaging' it into p-code (packed code). Compiling forward basically does the same thing but packages the other relevant code that the selected object extends. If compiling forward is not done, the classes that are used in the extension of that selected class will not see the new changes to the code as their p-code will not be updated. When there are discrepancies, it can cause the AOS to crash.

CLARIFICATION ON WHEN TO USE THE COMPILES:
All objects can and should be compiled upon import. The system should do that automatically with the import functionality but I have seen it a few time where this does not happen so I do it manually. as well just to be sure. Only items that are extending other classes need to be compiled forward.

Compile forward actions are only needed for objects (classes) that are inheriting other classes. Compiling forward should be considered an exception type compile. A compile forward can be identified as being needed by looking at the classDeclaration method of the class (see below). If this is not done, it can cause the application to crash. So if the system is crashing after a recent promotion and the code base is the same, make sure to compile forward the appropriate objects.

Hope that helps clear up any confusion on when the types of compilations are needed.

This post isn't intended to go into details about the compilations and bytecode updating. See Martin Drab's post below for more detail. His posts are always very solid.
http://community.dynamics.com/product/ax/axtechnical/b/goshoom/archive/2012/01/22/x-compilation.aspx 

HOW TO DO THESE COMPILATIONS:
Here is how to do these:
  1. Compile the objects individually (Figure 1)
  2. Compile the objects as a group (Figure 2)
  3. Compile the entire application from the AOT (Figure 3)
  4. Compile the entire application from the front end (Figure 4) 
  5. Compile forward the object of interest (Figure 5) 
Figure 1 - Compile items individually

 Figure 2 - Compile items as a group


 Figure 3 - Compile the entire application from the AOT

Figure 4 - Compile the entire application from the front end (under system administration module)




Figure 5 - Compile forward option. This option will not be available for objects not extending other objects



2 comments:

  1. Hello! It's a wonderful article, thank you for explanation of compile and compile forward in ms dynamics AX system. I'm a beginner and want to get more knowledge about the topic.

    ReplyDelete
  2. Hello guys! Thanks that you wrote about ax dynamics. It's little bit hard for me, because it's just a beginning:)

    ReplyDelete