Tuesday, January 8, 2013

How to debug the X++ code that is compiled to CIL?

One of the neat features of Dynamics AX 2012 is that it provides a way to compile X++ code to IL which then can be consumed by Microsoft .NET framework and  in return enhances the performance. But this brings some complexity to the issue identification and debugging efforts. In Dynamics AX 2012 client, if you receive an Infolog message which is not very meaningful and the double click on that message does not take you to any code, it is very likely that the code that you are running during your process is compiled into IL using this new feature. One way to get around this issue and to debug the System Operations Framework is to make the following change on runServiceOperation function of SysOperationRPCFrameworkService  class:


public static container runServiceOperation(ClassId controllerClassId, container packedController)
{
    // Use the runas API to transition to a CLR session
    new XppILExecutePermission().assert();
    
    // Disable this piece of Code - AK
    /*return SysDictClass::invokeStaticMethodIL(classStr(SysOperationServiceController),
                                        staticMethodStr(SysOperationServiceController, runServiceOperation),
                                        [controllerClassId, packedController]);*/
  
    // instead make this call - AK
    return SysOperationServiceController::runServiceOperation([controllerClassId, packedController]); 
}

After making this change, you will be able to double click the Infolog message and put a breakpoint and trace the call stack to find the underlying issue that causes the Infolog message.

4 comments: