Debugging standard X++ code is quite straight forward, open the code, set a breakpoint, run and debug.
But debugging X++ code running in CIL is different, it requires more work.
Service operation in Dynamics AX 2012 runs in CIL, you'll need to debug them from Visual Studio.
1. Open Visual Studio
2. Show the Application Explorer (View > Application Explorer)
3. Browse to the code you wanted to debug (Eg. the service operation)
4. Set a breakpoint
5. Attach the Visual Studio debugger to the Dynamics AX server process (Ax32Serv.exe)
(Debug > Attach to process ...)
6. Click on the "Select" button and choose "Managed (v4.0) and click "OK"
7. Select the Ax32Serv.exe and click "Attach"
(If you can't see this process, check the checkbox 'Show processes from all users')
8. Run the service operation process and when it reach the breakpoint, it will stop at the code in Visual Studio, you can then debug from there.
Setting breakpoint in Indo.add() or when Exception occur
In AX, one of the common technique to debug error is to put a breakpoint in Info.add(), this technique applies to service operation debugging as well (browse to Info.add() in Application Explorer, open the code in Visual Studio and set the breakpoint).
Another option would be to check the option for Exception.
(Debug > Exceptions ... > Check the checkbox for 'Common Language Runtime Exceptions')
Dynamics AX 2012 CIL debugging ref: http://msdn.microsoft.com/en-gb/library/gg860898.aspx
Remote debugging
The debugging of CIL doesn't always have to be done from the AOS hosting machine itself, it can be done remotely as well.
1. At the AOS hosting machine, go to "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Remote Debugger\x64"
2. Run the "msvsmon.exe" and leave it running there
3. On the remote machine (Eg. your laptop), start up Visual studio, follows Step 2 - 8 above, with an additional step at Step 5 - At the 'Qualifier', click on the Browse and select the AOS hosting machine.
Load Symbols
When you step in the code/method, if you're prompted to locate the code, you'll need to load in the symbols.
1. Go to: Debug > Options & Settings ... > Debugging > Symbols
2. Add this folder to cache: "C:\Program Files\Microsoft Dynamics AX\60\Server\[DynamicsInstanceName]\bin\XppIL\source"
*Change the [DynamicsInstanceName] to your instance name
In order to debug X++ code in Visual Studio You also need to make sure the following is in place:
ReplyDelete1) The AOS Server Configuration allows breakpoints to be set on code running server side. Make sure the AOS has restarted and the Server/INSTANCE/bin/XppIL/Source has xpp-files in it.
2) Enable Just my Code (managed only) needs to be ticket OFF. Option is available under the menu Tools\Options...\Debugging