How To Debug D365

Share this:

Do you need to debug D365? Are you a developer and you are not sure which service to attach to? In Microsoft Dynamics 365 for Finance and Operations there are a couple of different services that you can attach to, depending on how the system is running. In this article I will explain how to debug D365 and explain why there are two services.

Use Visual Studio To Debug D365

First, I will explain how to debug using Visual Studio.

Step1: Start Visual Studio as ‘Run as administrator‘. Do this by clicking in the windows start button, and typing in ‘Visual Studio’. When the application shows up in the search results, right click on the application and select ‘Run as administrator‘.

Add Breakpoints

Step 2: Add some breakpoints to either the base Microsoft code, or open a project and add breakpoints to your code. For example, go to the Application Explorer window. If you do not see this window, you can re-open by selecting View>Application Explorer. Then use the search bar at the top to type in ‘SalesTable’. Scroll down until you find the ‘SalesTable’ table. Right click on the object, and select ‘View code‘. Then put your cursor on some line of code. To add a breakpoint you can click in the grey vertical bar just to the left of the line of code. Or you can push the ‘F9‘ key, which is the shortcut to add a breakpoint.

Attach To Process

Step 3: Attach to process. To debug D365 we need to attach to the existing process that is already running on the machine. To do this, go to Debug>Attach to Process.

Step 4: Select the process. In the dialog that opens up, select Show processes from all users. Then select either ‘w3wp.exe‘ or ‘iisexpress.exe‘.

D365 can run in either service, which is confusing. So start by looking for the service iisexpress.exe. Attach to this process if you find it. If you do not find iisexpress.exe, look for w3wp.exe and attach to that process. If you don’t find either, make sure the ‘Show processes from all users‘ checkbox is checked and that your D365 website is running. You may need to start the website if it is not running. Before I cover the troubleshooting steps, I will finish explaining the steps if you do see the service. If you are able to find one of the two services, select the service, then click the ‘Attach’ button. Now you have begun to debug D365. You can stop reading here if you would like. The rest of the article explains why there are two services.

The Difference Between IISExpress and W3WP

Why do sometimes I need to attach to IISExpress and other times I need to attach to W3WP? To understand this we need to first look at how D365 works. Microsoft Dynamics 365 for Finance and Operations runs as a website, hosted in IIS (Internet Information Services). To see this, go to Windows Start Button on a cloud hosted machine. Then type in ‘iis‘. Select the application ‘Internet Information Services (IIS) Manager‘.

In the form, that opens, expand the nodes in the left navigation pane until you see ‘AOSService‘ under ‘Sites‘. This is the website that contains D365. If this website is stopped, then D365 will not function. Clicking on the link under ‘Browse website’ will take you to the D365 front end.

When this a website is running in IIS, it utilizes what is known as a worker IIS worker processes. And these worker processes show as w3wp.exe. You can actually have more than one running on a machine. Therefore, if the AOSService website is started, this means you need to attach to w3wp.exe in Visual Studio to debug D365. If you see multiple w3wp.exe services, you can actually multi-select and attach to all of them. Only the one running the AOSService is needed, but to ensure you have selected that service, you can select and attach to all of them. To learn more about the w3wp process, you can read further on stackify.

IISExpress

What does it mean if I only see IISExpress.exe in the list of services? IISExpress is a lightweight version of IIS. Visual Studio will start IISExpress when it needs to run or debug D365, and the w3wp.exe is not currently running. It is common to see this service running on a developer machine.

It will start up if you open a Dynamics 365 Project and then click on the Play button in Visual Studio. IISExpress will also open if you select a table from the Application Explorer, right click, and select ‘Open table browser’. However, now there is an even easier way. In Visual Studio, go to Dynamics 365>Restart IIS Express. This will start the service if it is not currently running.

You can actually see that IISExpress is running, rather than w3wp, by clicking on the carrot in the bottom right corner of your screen. This shows you processes running on your computer, and IISExpress is visible here.

Stopping IISExpress

Important note! It is not recommended that a user switch from using one service to another. I have learned from Microsoft, that issues can occur if you switch from on service to another. In general, you can let Visual Studio run as IIS Express and that is fine. If you really need to stop the service from running as IIS Express, below is the steps to stop the IIS Service. Followed by steps to start the W3WP service. Again, this is not actually recommended.

In order to debug D365 in the W3WP service IIS would first need to be stopped, as they both cannot run at the same time. Follow these instructions to stop the IISExpress process. Again, this is not recommended. Select the arrow in the bottom right corner of the machine, then right click on the ‘IIS Express’ icon. Then select ‘Exit’.

Starting W3WP

Next, click on Windows Start, and type IIS. Select the IIS Manager application from the results. Expand the nodes until you have the AOSService website selected. You will notice that it is stopped. This is because the AOSService website cannot run in IIS at the same time that it is running in IISExpress. Now that we have stopped IISExpress we can start the AOSService website. Click on the Start’ button under Manage Website.

Most likely when you try to run this website, you will receive this error message.

This is because when IISExpress is running, it stops the World Wide Web Publishing Service. So before we can start the website, we first need to start this service.

To Start the service, go to Windows Start button, then type in ‘Services‘. Select the Services application.

Find and select the World Wide Web Publishing Service and then click the ‘Start‘ link.

Now go back to the previous step, and click Start in the IIS Manager to start the AOSService website. This will also start a w3wp.exe worker thread. You can now attach to this process in Visual Studio to debug D365.

Conclusion

In order to debug D365, you need to attach to a process within Visual Studio. However there are two options to chose from. IISExpress.exe and W3WP.exe. In this article we explained how you can attach to whichever one you see is available. In addition, we looked at what these processes are, and how you can tell which one is running. Having this deeper understanding can prevent confusion in the future.

Peter Ramer
Peter Ramer is a part of the Managed Application Services team at RSM working on Microsoft Dynamics 365. He focuses on the Retail and Commerce industries. When he is not solving problems and finding ways to accelerate his clients' business, he enjoys time with his three kids and amazing wife.

Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑