Remote debugging can be a huge time-saver when dealing with a hard to reproduce bug, or trying to track down a Works on My Machine issue. I mean, what's better than stepping through the code on the remote machine that's having the problem?
However, the hardest thing about remote debugging isn't actually using it - it's getting it correctly configured between your local (debugging) machine and the remote host. Luckily the MSDN site has a pretty solid How to: Set Up Remote Debugging guide that can get you most of the way there.
Remote debugging monitor
The key set in getting remote debugging to work is firing up the Remote Debugging Monitor (RDM) on the machine that is being debugged... that is, the remote box. The guide does a great job of explaining how to install the RDM utility so I'll not go into that.
What the guide doesn't explicitly spell out is that you need to launch the RDM as a user who also has administrative access on your local machine. Let me explain how I did it wrong.
- Remote Desktop into remote web server (Windows Server 2003 SP1) as
Administrator.
Started RDM utility. - Launched VS 2005 on my local dev box (running Vista w/UAC enabled).
- Opened the solution for a web application that was running on the remote web server.
- Started a debugging session from VS (Debug - Attach to Process) and attached to the remote machine, being sure to use a Qualifier1 of Administrator@WebServerBox. (as seen to the right)
- When I tried to attach - ERROR!
The error message was pretty helpful, but didn't provide an obvious solution.
Unable to connect to the Microsoft Visual Studio Remote Debugging Monitor named 'Administrator@WebServerBox'. The Microsoft Visual Studio Remote Debugging Monitor on the remote computer cannot connect tot eh local computer. Unable to initiate DCOM communication. Please see Help for assistance.
The solution: do it the right way
The thing I messed up was all the way up in step #1. You see, on my local (Vista) box I'm running as myself - username: StevenHarman. However, when I RDCed into the web server I logged in using the Administrator account. The problem with that is, the Administrator account on the web server does not have access to my local machine.
Since I'm running Vista with UAC enabled, I've disabled the built-in Administrator account. So when the RDM tried to connect to a DCOM component on my local box, it failed because the process didn't have rights to do so.
To fix this problem I just needed to launch the RDM process using an account that does have access to my local machine and also has admin rights on the remote machine. So I temporarily elevated the rights of my StevenHarman account on the server, and then opened a new RDC connection as StevenHarman. Once connected I repeated steps 1 - 5 (as listed above), but this time I used StevenHarman@WebServerBox as the Qualifier in step #5.
Hooray, it works!
This time instead of seeing an error in step #6, I successfully connected to the remote machine and was then able to attache to the w3wp.exe process (the asp.net worker process). Within a few minutes I was able to track down the pesky but that started this whole thing.
The bug ended up being a typo in a RegExp I was using... duh!