Debugging in NAV 2009


UPDATE 25 August 2010! You cannot use the Express version of Visual Studio 2008 SP1 to debug Microsoft Dynamics NAV 2009. However, a useful and free visual debugger with slightly limited functionality - DbgClr.exe - can be downloaded as part of the .NET Framework 2.0 SDK: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=fe6f2099-b7b4-4f47-a244-c96d69c35dec

--- 

UPDATE 18 December 2009! The most up-to-date version of this content is available in the Microsoft Dynamics NAV 2009 Developer and IT Pro Help on MSDN: http://msdn.microsoft.com/en-us/library/dd301071.aspx.

---

 
UPDATE!!! Debugging is not available in the Marketing Beta, so if you have access to a later build you can try this out. If not you will have to wait for RTM.
Also note that SP1 for either Visual Studio 2005 or Visual Studio 2008 is required.
---

In this post I will give you a example on how to debug in NAV 2009.

1. EnableDebugging in CustomSettings.config found here: C:\Program Files\Microsoft Dynamics NAV\60\Service

image

2. Now Restart the “Microsoft Dynamics NAV Server” service

image

3. Now we have debugging enabled. Now start the RoleTailored client. This will take a bit longer to start up, because C# files are generated for each of the objects. (Pages, Codeunits, Reports etc.)

4. Now we need to find a place to debug. In this example I will make a codeunit with a simple message and add this to an action on the Customer list.

5. Create a Codeunit. Ex. 50000

6. OnRun trigger place the following code: MESSAGE ('Debug test')

image

7. Save and compile Codeunit 50000.

8. Now let us add this codeunit to a action. Design page 22 and navigate to the Actions on page 22.

9. Insert a new action below the the Customer Action group

image

10. Hit F9 and enter this code on the Debug test -  OnAction trigger: CODEUNIT.RUN(50000);

image

11. Save and compile page 22

12. OK we now have all code completed so now let us set a breakpoint in Visual Studio.

13. Navigate to “C:\ProgramData\Microsoft\Microsoft Dynamics NAV\60\Server\MicrosoftDynamicsNavServer\source\Codeunit”

14. Assuming that you have Visual Studio installed, (In my case I’m using Visual Studio 2008 with SP1) open Codeunit50000.cs

image

15. If you have UAC turned you will need to open Visual Studio with “Run as administrator”.

16. Now we need to attach the NAV service. Select “Debug / Attach to process…”

17. Attach Microsoft.Dynamics.Nav.Server.exe

image

18. Your screen should now look like this:

image

19. Now add a break point on the message “Debug test”

image

20, With this done now let us go to RoleTailored client.

21. Navigate to Customer List and see that you have a new action called “Debug test” under “Related Information”

image

22. Now select “Debug test”

23. Visual Studio will come back in focus with the breakpoint selected.

image

 

 

 

 

 

 

 

 

 

 

 

24. Now try to hit F5 and debugging will continue and RoleTailored client will come back in focus and show the message “Debug test”:

image

Thanks,

Claus Lundstrøm, Program Manager, Microsoft Dynamics NAV

Comments (3)

  1. Heinz D says:

    You stated, that debugging the Service Tier will work with Visual Studio Express Edition. Can you please explain how you get this work?

    Thanks

    Heinz

  2. Alex says:

    I’m trying this on a NAV2009 with VS2008 installed. I cannot find

    "C:ProgramfilesMicrosoftMicrosoft Dynamics NAV60ServerMicrosoftDynamicsNavServersourceCodeunit" directory?

    Do you have to run this on the server?

  3. navblog says:

    Just to verify, you are looking in the C:ProgramData directory, not the "C:Program Files" directory, correct?

    To find the location of the C# files, do the following:

    After you enable debugging and start the RoleTailored client, open the Event Viewer.

    In the Application log, find the entry that has MicrosoftDynamicsNAVServer for its Source and has the following description:

    Service: <service name>

    Source files for debugging are available under <source file location>

Skip to main content