Visual Studio 2008 – Remote Debugging

September 17, 2011

I was working on a project today which involved debugging a web service, being called from separate application which we also needed to debug at the same time (So we would workout what part of the system was playing up).

The client application was already setup to call the web service on our test server. We wanted to retain this in order to replicate the production environment as closely as possible. The test server did not have visual studio installed, also, we wanted to run the web service via IIS – Not Visual Studios built in web server.

To allow us to debug from my desktop PC, I enabled remote debugging on the test server, allowing us to attach to th IIS application pool process

Step-by-Step Walk Through…

  1. From the client machine, copy folder ‘Remote Debugger’ from C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ to the server at any convenient location
  2. Run the appropriate version (X86/x64) of the listener – ‘msvsmon.exe’ on the server, found in the ‘Remote Debugger’ folder – This needs to be run as Administrator (Right click, run as administrator)
    When it runs, you should see the log, with the first line showing:
    ‘MSVMON started a new server named ‘username@servername’. Waiting for new connections’
  3. Your application will need to include PDB (Program Database) files – These include source file names, their lines and local variable names.
    See for a full explaination)
    If you are used to right clicking your project name and selecting publish to deploy your site/web project, be aware that this method will always compile a release build which will exclude the PDB files. Instead, you’ll need to use one of the following methods:A) ASP.Net Compilation Tool:
    See detailsB) Build in debug mode, and manually copy/ftp the files to the server.
  4. You are now ready to commence debugging. Open Visual Studio on your client machine, select ‘Debug’ > ‘Attach to Process’. Transport should be set to ‘Default’. Enter the server name (The server you ran msvsmon.exe on) in the Qualifier box and hit enter. You will notice this will be resolved to username@servername
  5. From the list of available processes, select W3WP.EXE (IIS Worker Process) and click ‘Attach’. You will recieve a security warning – Click ‘Attach’
  6. If all has gone well, you should now be able to set a break point in your code, run the code (By opening the web site at its server/remote address) and see he break point hit.

Worth Mentioning…

  • In our scenario, we were running Windows 7 client machines connected to Windows Server 2008 Web Server
  • The code on the server needs to be the same as the code you arer using to debug – Otherwise line numbers will likely be out of sync, making debugging very difficult!
  • Debug symbols (.PDB Files) are stored in your app at: \obj\Debug

Trouble shooting…
(Only 1 suggestion right now – I’ll add to this if/when I discover others!)

  • If you cannot see W3WP.EXE in the ‘Attach to process’ dialog, ensure you have:
    • Ticked ‘Show processes from all users’
    • Ticked ‘Show processes in all sessions’
    • Ran (Browsed to) the application at least once (Or indeed, any app on the server) to load the worker process



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: