X++ Debugging Tips and Tricks #2 – xSession::xppCallStack()

X   Debugging banner 2

In the first trick we saw how to set a breakpoint in the add method on the info class. This enables us to get the context of a single error.   But sometimes error messages come in hoards and stepping through each of them is not practical. Suppose you have hundreds or even thousands of errors occurring, and you want to trace where they are coming from. This trick shows you how.

This trick requires code instrumentation – I will strongly discourage using this trick on a production system. Only use this trick in a test or development sandbox!        
The system APIs available in Dynamics AX are fantastic. There is hidden gem of an API that gives access to the current X++ call stack in the form of a container. This makes it relatively simple to include the call stack in the error messages shown in the Infolog. Just insert this line of X++ code in the add method in the info class just after the variable declaration section:

_txt += con2Str(xSession::xppCallStack()); 

Now run the scenario, and inspect the Infolog. It will include the call stack for each message, and will look something like this:


With this information it is much easier to browse through the many messages in the Infolog and find variations in the call stacks.

This post is provided AS-IS, and confers no rights or warranties.

Comments (3)

  1. Kenny Saelen says:

    Nice post!

    What I usually do is use the xClassTrace class for this. Then you can put this in your code and it will only execute if tracing is enabled and you can find your message in your event viewer.

    if(xClassTrace::isTracingEnabled() && xClassTrace::isTracingStarted())


           xClassTrace::logComponentMessage("componentname", con2str(xSession::xppCallStack());


    That way you can enable tracing in production without overhead.

    kind regards,


  2. Denis says:

    xSession::xppCallStack() doesn't work in IL and this can be issue for AX2012