Showing posts with label Debug. Show all posts
Showing posts with label Debug. Show all posts

Tuesday, January 8, 2013

Start Debugging in AX 2012 - for non-developers

In order to start debugging the Dynamics AX code first you need to enable debugging for the current user. You can enable the debugging for the current user by setting the Debug mode to "When Breakpoint" under "File/Tools/Options/Development/Debug" tab.


If you don't know where to start debugging an issue that throws an Infolog message, you can put a breakpoint to Info:add class.This will make the process stop for debugging for every infolog message.


Then in the debugger, when the process stops you can traverse the callstack in order to find the underlying issue.



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.