Rajesh kumar’s Blog

If you have knowledge, let others light their candles at it.

Debug the .Net code from remote machine

Posted by Rajesh Kumar on July 11, 2011

Debugging the code from development environment is very easy. The actual problem starts when we want to debug the code that is already deployed in some system (local system, remote system, production server etc.).

It’s because, such environments will not have any SDK installed. However, Microsoft still makes developer’s life easier by allowing us to debug such deployed code from our local machine. This article tries to explain it.

Limitation: Visual Studio Professional, Premium and Ultimate versions can be used to debug the code. Visual studio Express does NOT allow you to debug the code through a process.

What needs to be done?

We need to do two things for debugging from remote machine:

  • Preparing remote system.
  • Attach the deployed code to source code from local machine.

What are required?

We need two things to start the remote debugging:

  • PDB files
  • MSVSMON.exe
  • You must have access to the remote system.
  • Your remote and local system must be in same domain (or in trusted domain list).

If you are not sure what are pdb files, A program database (PDB) file holds debugging and project state information that allows incremental linking of a debug configuration of your program. A PDB file is created when you build with /debug. (extracted from MSDN).

MSVSMON (Microsft Visual Studio remote debugging monitor) acts as an agent from remote system for Visual Studio. It comes with SDK installation and is generally available at C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Remote Debugger\x64\msvsmon.exe. (x64 indicates your operating system mode).

The most important point to remember is, we must have the same version of PDB files of the original source code deployed on remote machine. Please read this article for more information.

Preparing remote system:

Please feel free to copy the entire x64 (as mentioned above) to the remote machine where the code is deployed and run the msvsmon.exe file. You may see the screen as given below:


Now, move all .pdb files to the bin directory of the deployed application. Now, it’s the time to identify the process id of the application that you want to debug. Task Manager shows list of processes running on the current (remote)and its Ids against them. It is very straight forward for finding process Ids for services or exe files. However, it is bit different for web application. Please read my article here to find out more.

Attach the deployed code to source code from local machine:

Open the source code in Visual Studio. Go to “Debug –> Attach to Process” option. You should be able to view “Attach to Process” window.

Leave the “Transport” to Default. In the “Qualifier” text box, type the text as <DomainName\UserName@ServerName> as displayed in msvsmon.exe window given above and then hit Enter key.

With this, Visual studio makes the connection to remote system and gets all processes list running on remote machine. You may see the screens in local machine and remote machine as below:

image image

Now chose, the right process Id and hit “Attach” button. With this, you are ready to debug the code. Happy debugging Smile.

References: MSDN


5 Responses to “Debug the .Net code from remote machine”

  1. nikon d700 said

    nikon d700…

    […]Debug the .Net code from remote machine « Rajesh kumar’s Blog[…]…

  2. Heya just wanted to give you a quick heads up and let you know a few of the
    pictures aren’t loading properly. I’m not sure why but I think its a linking issue.
    I’ve tried it in two different internet browsers and both show the same outcome.

  3. Hey! I could have sworn I’ve been to this site
    before but after browsing through some of
    the post I realized it’s new to me. Anyways, I’m definitely delighted I
    found it and I’ll be bookmarking and checking back often!

  4. Good day! This is kind of off topic but I need some help from an established blog.

    Is it very hard to set up your own blog? I’m not very techincal
    but I can figure things out pretty fast. I’m thinking about setting up my own but
    I’m not sure where to start. Do you have any points or suggestions?
    With thanks

  5. http://manchu.dothome.co.kr/

    Debug the .Net code from remote machine « Rajesh kumar’s Blog

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: