Remote debug Windows service using VS2012

I tried to find an answer to this question before posting this question. I have a windows service running on a different machine. I wrote a service in C # and the directory from which the service executable is executed contains both executables and debug files (.pdb). I am trying to remotely debug a service for the first time using VS 2012 remote debugging. I can successfully connect to the service. However, since this is my first time, I am not sure what I can do next. I hit the pause button and this pauses the service at the ServiceBase.Run (ServicesToRun) line, which is not very convenient for me. The service has a timer that is laid out every 30 seconds and runs the code in the timer event.

My question is, is there a way to execute the code using the debugger in a scenario like this. Do I need to have some debug code already in my codebase so that when the debugger is connected, it will take me to a place in the code from where I can step through the code?

Thanks Andrew.

+3


source to share


2 answers


There are several ways to debug your developed remote application or Windows service. If you were on your machine (local) that would be easy to debug.

System.Diagnostics.Debugger.Launch();

      

But since you are on a different machine, it depends on how your both machines are connected. This means that you have some limitations on debugging the remote application / services.

A quick search gave me the following result, which I found useful,

You can use Remote Debug Monitor which visual studio uses to connect to a remote device and debug. You can get a clear instruction here on How to start the remote debug monitor .

There is another tool that allows you to debug a remote application once it is configured correctly. But it has some restrictions or conditions that you must comply with.

Here is a tool named Remote Tool , you can find the detailed installation process from MSDN here How To: Configure Remote Debugging .

The prerequisites for using this tool are clearly stated here. But I will rephrase them again for quick reviewers.

Prerequisites for using Remote Tool for Visual Studio



  •   
Debug on a remote device: The

   remote device and the Visual Studio computer must be connected over a network or directly connected using an Ethernet cable. Debugging over the Internet is not supported .
   The Remote Tools for Visual Studio 2012 must be running
   on the remote device. You must be an administrator to install remote tools on the remote device. To communicate with remote instruments, you must have user access to the remote device.

Feel free to share if you fall into the best and working solution.

0


source


Thanks for your reply. It reminded me to post my solution here for others like me.

The solution is simple (it's always when you know it).

Make sure you are using the same code on the target computer as you are using Visual Studio. It must be the same build and version, otherwise the debugger won't hit your breakpoints. Make sure you have breakpoints set where you want the debugger to break execution. Then attach to the target machine process and wait for the timer to start and start the process where the breakpoint is set.



Hope it helps.

Andrei.

0


source







All Articles