Tuesday, 7 October 2008

How to do remote debugging with the Visual Studio 2008 Remote Debugger Service (Msvsmon.exe)

There is always a problem that will crop up on one of your servers that you just CANNOT reproduce at all. To solve pesky problems like this, you can make use of the remote debugger service of Visual Studio. What's more, you can debug without running a setup package at all on dev or production servers. Instead, you can just run msvsmon.exe from a file share without even installing anything. This will definitely keep the network guys happy!

Typically, you can get msvsmon.exe file from the following path on your development machines that already have Visual Studio 2008 installed:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger\x86\msvsmon.exe

When you run Msvsmon.exe, it just shows up on the server as a windows application on your server (See screenshot). You can also run it as a Windows Service so you don't need to log onto the server to start it up.




In Visual Studio on your local machine, you then just put in a fully qualified remote server name in "Attach to Process" dialog. Now you can debug the remote machine to your hearts content (make sure you're a debugger user or remote admin otherwise you will get access denied errors).

Just a reminder - if you are debugging ASP.NET on a 2003 server and above, there will be 1 w3wp.exe process for each of your application pools. It may be hard to find out which w3wp.exe process you want to debug as there may be many application pools. You can find out which w3wp.exe process is running your pool by a process of deduction (ie just by stopping the application pools you are not using. The one left is yours).

For the full goss, see http://support.microsoft.com/default.aspx/kb/910448. There is even a 17 minute tutorial on setting it up. See http://www.microsoft.com/uk/msdn/screencasts/screencast/313/visual-studio-2008-remote-debugging-with-msvsmonexe.aspx

Just keep in mind - you may be up for a long wait if the connection to your server is slow - especially if attaching a process in Atlanta! :o). There is a timeout option if you get timeout errors (you only get timeout errors in "No Authentication" mode as the "Windows Authentication" mode has an infinite timeout.)


2 comments:

olivierH said...

"you may be up for a long wait if the connection to your server is slow"
How do you define "long wait" and "slow"?
I try to remote debug an asp.net website with vs2008 and vista business/windows server 2008 on "recent" computers within a local network (4/5 PCs)

olivierH said...

"you may be up for a long wait if the connection to your server is slow"
How do you define "long wait" and "slow"?
I try to remote debug an asp.net website with vs2008 and vista business/windows server 2008 on "recent" computers within a local network (4/5 PCs)

After attaching, I get the message
"The target assembly contains no service types. You may need to adjust the Code Access Security policy of this assembly"

then I have to wait 60 sec to have VS2008 running again (debugging)

I found an article (somewhere??) that said I had to add the following;
using System.ServiceModel;

then, just before the first class of each project:
[ServiceContract(Namespace = "....foo....")]

and it works! no more warning or delays ...

I must add: I created a solution with 1 web site hosted remotely and 2 dll projects.
This problem does not occur with a "lonely" website.
Hope this helps.