Geeks With Blogs
Satya Srikant Mantha Reflecting DAX NET and SQL Server

A very intriguing issue came to me to debug .Net code called from X++ code in AX 2012. This was indeed a challenge to be nailed down. Luckily the tools and some concepts helped me to achieve this task. Here it goes...

We need to do a seamless debugging from AX debugger to Visual Studio back and forth. To enable this we need to first see if the dll to be debug is present in GAC then we might need to uninstall it from it due to the order of preference .NET loads the assemblies. The assemblies are first loaded from GAC and then the runtime checks for Public and Private Assemblies. Since the assembly in GAC is always compiled with runtime optimizations it is difficult to debug. We need to unhook this assembly from GAC and then move further relying on >NET assembly loading patterns.

Step 1: Remove the target assembly to debug from GAC. Before that stop all the AOS servers and close all the instances of programs which rely on AOT e.g. all clients and even visual studio now.

Step 2: Build your sample code which is present in AOT in debug mode and get the dll file along with PDB files.

Step 3: Place these files in the Server\..\Bin and Client\bin directories of AX installation.

Step 4: Configure Visual Studio:

Step 4.1: Configure Debugging Options. In Visual Studio Go to Debug -> Options and Settings -> Debug node -> General sub node and disable “Enable Just My Code (managed)”

clip_image002

Step 4.2: Specify the symbol loading directory options. Specify the locations for Client bin and server bin directories of the installation, remember to specify the correct instance of Server bin directory corresponding to your AOS.

clip_image004

Step 4.3: Configure the project for debugging

clip_image006

Step 5: Ready to go place your breakpoints in X++ and in .Net wherever necessary before this process...

Run the Visual studio project and it will invoke the AX client with your breakpoint hitting X++ code.. and when you do a step-in using F11 the Visual studio debugger will be active and from here onwards you would be able to debug the complete flow.

Debugging in seamless manner across debuggers is really very good feature and mostly underutilized, but by doing so we can have improved troubleshooting and saves a hell lot of time..

Stay tuned for more in Advanced Debugging..

Posted on Thursday, November 10, 2011 7:30 PM | Back to top


Comments on this post: Debugging .NET code called from X++ code in AX 2012

# re: Debugging .NET code called from X++ code in AX 2012
Requesting Gravatar...
good post! thank you!
Left by EmmaSilva on Nov 11, 2011 12:22 AM

# re: Debugging .NET code called from X++ code in AX 2012
Requesting Gravatar...
Dear Sir,

in your step #2 you seem to imply this .NET code is in an AOT visual studio project. If this is the case, you should NEVER copy the dll files manually into the GAC or the client/bin or server/bin. This deployment is done automatically, in your user's local appdata folder. If you place these dlls in your bin manually, you are overriding the new mechanisms in AX 2012.
Please see my blog post at http://daxmusings.blogspot.com/2011/09/ax-2012-net-assembly-deployment.html
Left by Joris.dg on Nov 11, 2011 2:44 AM

# re: Debugging .NET code called from X++ code in AX 2012
Requesting Gravatar...
@Joris: You are right in case of of our own custom dlls being referenced in X++ this might be the case.. However I was debugging a very specific dll from Microsoft which was built with optimizations enables and with no debug information. That made things difficult for me to debug.. whenever I was trying to debug the source was pointing to GAC which was undesirable..
Left by Satya Srikant Mantha on Nov 13, 2011 7:13 PM

# re: Debugging .NET code called from X++ code in AX 2012
Requesting Gravatar...
please clarify the above steps mainly for GAC.What is GAC i didn't get that word.
Left by Naresh on Dec 21, 2012 6:15 AM

# re: Debugging .NET code called from X++ code in AX 2012
Requesting Gravatar...
GAC stands for Global Assembly Cache.
Left by Shyamala on Jun 15, 2013 5:13 AM

Your comment:
 (will show your gravatar)


Copyright © ssmantha | Powered by: GeeksWithBlogs.net