Philippsen's Blog

Everyday findings in my world of .net and related stuff

AX2012 CIL debugging

Posted by Torben M. Philippsen on February 22, 2016

AS You know there are a lot of guides out there on how to debug CIL. However when problems occur I find that quite a lot are missing some important things. So here’s my shot at a guide on how to debug CIL code.

In AX2012 some code is run in CIL (Common Intermediate Language). In general it means that our x++ code is compiled into .net. For instance batchjobs and other serverside code is run in CIL (unless configured otherwise).
If You want to read more regarding the background please visit this link – X++ compiled to .NET CIL.

Sometimes a mismatch can occur between the x++ code and the CIL code, and in these cases, it is nice being able to debug. I will try to list some important things that You may want to concider/check.

  • You will have to use at least VS 2010
  • I would recommend doing a local debug session – meaning your visual studio should be installed directly on the AOS. You can setup remote debugging but that just opens for a whole lot of new problems. Keep it simple – keep it on the AOS.
  • If possible You will prefer to have exclusive access – meaning no other users should be logged on. When debugging serverside code, you will hit every breakpoint triggered accross users. This means if you are debugging in an area where a lot of users are working, you will have to struggle with breakpoints being hit in a way you can’t possible imagine.

In order to configure your environment for CIL debugging You need to do this:

  1. Install VS2010/VS2012/VS2013 depending on your ax version on the AOS
  2. Run the Microsoft Dynamics AX Setup and choose to install the Visual Studio Tools.
  3. Generate/locate the sources
    When CIL compillation is performed it outputs .xpp files in C:\Program Files\Microsoft Dynamics AX\60\Server\<AOS_INSTANCE_FOLDER>\bin\XppIL and source files for Visual studio here C:\Program Files\Microsoft Dynamics AX\60\Server\<AOS_INSTANCE_FOLDER>\bin\XppIL\Source
    On some occations I have experienced the the source folder does not exist. In these cases stop the AOS service, delete all contents of the XppIl folder, restart the AOS (Maybe You need to perform a full CIL before). If you are not doing local debugging, You will need to setup a share for this folder.
  4. Configure the AOS for debugging. Go to the Dynamics AX Server configuration tool and be sure that the following checkmarks are set
    serverconfig
  5. Launch visual studio in admin mode. Be aware that when VS connects to AX it uses the configuration from the client configuration tool. Make sure that you have set up the configuration you need – connecting to the correct layer etc (not important if you are just debugging).
    Launch the Dynamics AX Application Explorer to browse the AOT and set the breakpoints of your choice. When You double clikc a method a new solution is automatically created in solution explorer.
  6. Right click the newly created solution and select “properties”.
    properties
    Select “debug source files”.
    Add the path for the source files (local path or remote share)
  7. Now You are ready to attach Visual Studio to the AX32Serv process. Click the “Debug” menu item and select “attach to process”. Locate the AX32Serv process and attach to it. If VS is not in admin mode VS will now ask you to restart in elevated mode.
    attach
  8. Go back into AX and do the things you need in order to hit the breaktpoint.
  9. If You are not hitting any breakpoint you need to check, that you are set up to run code in CIL. Inside AX open a development environment. Go to Tools –> Options –> Development
    options
    Make sure that the checkbox “Execute business operations in CIL” is checked.
Advertisements

Sorry, the comment form is closed at this time.

 
%d bloggers like this: