Monday, July 18, 2011

Remote Debugging .NET Applications

From the past few days I have been stuck in resolving a bug which cropped up in one of my applications after it went to Production. The worst part was that it was a machine-specific issue and we couldn't reproduce it in any of our development systems. While trying to find a solution for this, I came across the concept of Remote Debugging.

Remote debugging is debugging a remotely running application through a development environment running on a system other than the one running the app. This is done by connecting the remote system to the system containing the development environment (in turn the debugger) through Sockets. Theoretically this is achieved in two steps -

  • The remote computer would open a socket and listen to debug instructions through it. These instructions are feed to the application that is being debugged and the application responds appropriately
  • The debugger would connect to the socket opened by the remote system and send instructions through it

Remote debugging can be used in many live situations. Examples include -

  • Debugging a machine specific issue which can't be reproduced on systems running the development environment (my exact requirement :))
  • Debugging applications which can run only on the server machine due to dependent third party libraries that cannot be used in the development machine

In this blog post, I will be focusing on Remote Debugging .NET applications through Visual Studio 2010. The screen shots correspond to a simple .NET application which would popup a MessageBox on a button click. Get the code here.

Configuring the Host Computer

The host computer is the computer containing the development environment. This is the system running Visual Studio 2010. To enable Remote Debugging, make sure the following ports are open on the host computer -

Ports
Protocol
Description
135
TCP
Required
500, 4500
UDP
Required if your domain policy requires network communication to be performed through IPSec

IPSec (Internet Protocol Security) is a protocol suite for securing IP communications authenticating and encrypting each IP packet of a communication session. Read more about IPSec here. However I am not going cover IPSec in this post.

You can check if the ports are open by using the telnet command at command prompt (telnet isn't installed by default on Windows 7. Install it from the "Turn Windows features on or off" section in the Control Panel).

Configuring the Remote Computer

To configure the remote system for debugging, either download and install the Microsoft Visual Studio 2010 Remote Debugger or copy the folder Remote Debugger from the Visual Studio install path, which is typically C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE. The Remote Debugger is available for three configurations - x86, x64 and ia64.

Visual Studio takes the .pdb files for debugging from the remote system for managed code. So copy the .pdb from the bin/Debug folder of the project to the remote system. Put this folder on share so that Visual Studio can access it later.

To enable Remote Debugging, make sure the following ports are open on the host computer -

Ports
Protocol
Description
135, 139, 445
TCP
Required
137, 138
UDP
Required
500, 4500
UDP
Required if your domain policy requires network communication to be performed through IPSec
80
TCP
Required for Web Server debugging

That's it; both the host and remote computers are up and ready for Remote Debugging.

Start the application on the remote system if it isn't running already. Also start the Visual Studio Remote Debugging Monitor on the remote system using the msvsmon.exe from the appropriate configuration folder in the Remote Debugger directory (The screenshot uses the x86 version).

Open the code in Visual Studio on the host system and select "Attach to Process". Typically Visual Studio identifies the .pdb file of the remote system if it can. If it doesn't, open the Modules screen from Debug -> Windows -> Modules. Check the Symbol Status of the .exe file which is being debugged and if it shows "Cannot find or open the PDB file" right-click on it and select "Load Symbols From" and specific the share path through the "Symbol Path".

Specify the breakpoints in the code and they would hit appropriately. There are two major bottlenecks in Remote Debugging -

  • The code from which the executable was built should be available at the time of debugging
  • The above mentioned ports should be open for debugging. Most of the developers wouldn't have administrative privileges on the client systems, so they would require people with sufficient privileges to open up these ports. However several organizations wouldn't prefer opening up ports for incoming connections

Before I conclude, here's an article from MSDN on how to Set Up Remote Debugging. Visit it if you would like a deeper insight into Remote Debugging.

30 comments:

Vee Eee Technologies said...

Thanks for the post. I liked it. Keep going I follow you.

sam fisher said...
This comment has been removed by the author.
Gannon Delacruz said...

The Purpose of Ports is to exclusively recognize different programs or procedures running on only one computer and thereby allow them to discuss only one physical relationship to a packet-switched system like the Internet.

Erich Ingram said...

There are a lot of factors why the .NET platform and .NET development is very popular among the masses.

Shariq Waseem said...

http://b2bad.in/Packers-and-Movers-in-Delhi/ @ Movers and packers in Delhi http://b2bad.in/Packers-and-Movers-in-Delhi/ @ Delhi packers and movers

Packers And Movers Pune said...

This is useful content. really apreciate it! Please Visit Our Webpage:
http://thebusinessplace.in/
Packers and Movers Pune, Local Household Shifting. Best Moving And Packing Services Now At Your Door In Pune @ TheBusinessPlace.in #PackersMoversPune Provides Packers Movers Pune, Movers Packers in Pune, Local Shifting, Relocation, Packers Movers Pune, Local Household Shifting, Office Shifting, Logistics and Transportation, Top Packers Movers Pune, Best Packers Movers Pune, Good Movers Packers in Pune, Home Shifting Pune, Household Shifting Pune, Cheap Top Movers Packers in Pune, Moving and Packing Service Company Pune.

Packers Movers Ahmedabad said...

I really enjoyed reading your blog, you have lots of great content.Please visit here:
http://packersmoversahmedabad.co.in/
We are expert in Handling, Movers Packers in Ahmedabad and Packing & Shifting of Household Goods, Office goods, Commercial Equipment and Car, Logistics and Transportation.
http://packersmoversahmedabad.co.in/packers-and-movers-vadodara-gujarat
http://packersmoversahmedabad.co.in/packers-and-movers-surat-gujarat
http://packersmoversahmedabad.co.in/packers-and-movers-gandhidham-gujarat
http://packersmoversahmedabad.co.in/packers-and-movers-rajkot-gujarat
http://packersmoversahmedabad.co.in/packers-and-movers-bhuj

the best packers and movers delhi/ncr said...

Packers and Movers in Noida @ http://www.hariharpackers.in/packers-and-movers-noida/

Packers and Movers in Delhi @ http://hariharpackers.in/

Packers and Movers in Faridabad @ http://www.hariharpackers.in/packers-and-movers-faridabad/

Anil Doot said...

Thanks for all your information.Website is very nice and informative content.


Packers and Movers in Bangalore@

http://safespeedpackers.com/


Packers and Movers Bangalore@

http://safespeedpackers.com/index.html


Packers Movers in Bangalore@

http://safespeedpackers.com/packers-and-movers-in-Bangalore.html


Packers and Movers in Kolkata@

http://safespeedpackers.com/packers-and-movers-in-kolkata.html

Anil Doot said...

Thanks for all your information.Website is very nice and informative content.


Packers and Movers in Bangalore@

http://safespeedpackers.com/


Packers and Movers Bangalore@

http://safespeedpackers.com/index.html


Packers Movers in Bangalore@

http://safespeedpackers.com/packers-and-movers-in-Bangalore.html


Packers and Movers in Kolkata@

http://safespeedpackers.com/packers-and-movers-in-kolkata.html

Anil Doot said...

Very nice blog ,content is very fantastic and informative .For More Visit:

Packers and Movers in Ahmedabad
http://www.mangalmaypackers.co.in/
Packers and Movers Baroda
http://www.mangalmaypackers.co.in/packers-and-movers-baroda.html
Packers and Movers in Bharuch
http://www.mangalmaypackers.co.in/packers-and-movers-bharuch.html
Packers and Movers Valsad
http://www.mangalmaypackers.co.in/packers-and-movers-valsad.html
Packers and Movers in Banaskantha
http://www.mangalmaypackers.co.in/packers-and-movers-banaskantha.html

Anil Doot said...

Car Transport in Gurgaon@

http://www.carcarriersgurgaon.com/


Car Transport in Gurgaon@

http://www.carcarriersgurgaon.com/index.html


Car Transport in Delhi@

http://www.carcarriersgurgaon.com/delhi.html


Car Transport in Bangalore@

http://www.carcarriersgurgaon.com/bangalore.html

Packers And Movers Bangalore said...

PACKERS AND MOVERS IN BANGALORE know the estimation of your money and along these lines MOVERS AND PACKERS BANGALORE give you the alternatives of the sensible, sensible and useful organization suppliers so you can go for them as per your needs, prerequisites and their deeds. You can now successfully consider the cost of your development through the diverse quotes gave by the clearing associations recorded with us.
Packers And Movers Bangalore

Packers Movers Hyderabad said...

really a vry nice blog i really appreciate all your efforts ,thank you so mch for sharing this valuable information with all of us.
Packers and movers Hyderabad touch base at most elevated amount by virtue of our movement in our organizations. #Movers #Packers #Hyderabad get routinely overhauled with the new transportation vehicles and pressing materials available in business.
http://packersmovershyderabadcity.in/

Ramniwas jakhar said...

http://packersmoversbillforclaimpune.blogspot.in/ http://hinjewadipackersandmovers.co.in http://marutipackersmoverspune.in http://marutipackersandmoverspune.in

Ramniwas jakhar said...

http://packersmoversbillforclaimpune.blogspot.in/

http://hinjewadipackersandmovers.co.in

http://marutipackersmoverspune.in

http://marutipackersandmoverspune.in

Raksha Jain said...

Packers And Movers Mumbaithat just offer their administrations for abroad movement or universal #moving. In the event that you are migrating from Mumbai to another nation then such organizations can give huge help to you and your movement.
http://packersmoversmumbaicity.in/packers-and-movers-kolhapur-maharashtra

Kavya Sharma said...

I really enjoyed reading your blog, you have lots of great content.Please visit here:http://packersmoverspatna.in/

http://packersmoverspatna.in/packers-and-movers-gaya

http://packersmoverspatna.in/packers-and-movers-begusarai

Packers And Movers Patna

based company provided that Movers And Packers Patna Services for Office, Home, Local or domestic and commercial purposes.

Yash said...

If i share this blog weblogic Server Training in Chennai aims to teach professionals and beginners to have perfect solution of their learning needs in server technologies.



packers and movers Kanchipuram chennai

Riya Jain said...

Thanks again for the article.Really looking forward to read more. Will read on..Packers And Movers Bhopal
http://packersmoversbhopal.in/packers-and-movers-indore
http://blog.packersmoversbhopal.in/

Suraj Baba said...

Packers and Movers Hyderabad
Packers and Movers Bangalore
Packers and Movers Pune

Suraj Baba said...

Packers and Movers Mumbai
Packers and Movers Gurgaon
Packers and Movers Delhi

Suraj Baba said...


Packers and Movers Chennai
Packers and Movers Noida
Packers and Movers Navi Mumbai
Packers and Movers Thane
Packers and Movers Ghaziabad
Packers and Movers Faridabad

movein said...

Packers and Movers in Pune
Packers and Movers in Bangalore
Packers and Movers in Gurgaon
Packers and Movers in Thane
Packers and Movers in Navi Mumbai

Century Packways said...

You have shared very nice information regarding this social media. Really I got some new things from here. Movers And Packers Pune

deepak said...


Packers and Movers Gurgaon
Packers and Movers Delhi
Packers and Movers Chandigarh
Packers and Movers Dehradun
Packers and Movers Faridabad
Packers and Movers Surat

deepak said...


Packers and Movers Bangalore
Packers and Movers Hyderabad
Packers and Movers Ahmedabad
Packers and Movers Ambala
Packers and Movers Amritsar
Packers and Movers Bhatinda

Naviya Nair said...

I have read your blog its very attractive and impressive. I like it your blog.

.Net Training in Chennai | .Net Online Training | Dot Net Training in Chennai

Dot Net Online Training | LINQ Online Training

Naviya Nair said...

I have read your blog its very attractive and impressive. I like it your blog.

.Net Training in Chennai | .Net Online Training | Dot Net Training in Chennai

Dot Net Online Training | LINQ Online Training

Century Packways said...

No matter where you move to around the world, you have the backing of Century Packways Moving as your trusted relocation partner.
Packers and Movers in Pune
Movers And Packers Pune
Movers And Packers