3
votes

I've tried to find an answer to this before posting this question. I've got a windows service running on another machine. I've written the service in C# and the directory from which the service executable runs holds both executable and debug files (.pdb). I'm attempting to remote debug the service for the first time using VS 2012 Remote debugging. I'm able to attach to the service process successfully. However, as this is my first time I'm not sure what I can do next. I've clicked the pause button and that pauses the service on the line ServiceBase.Run(ServicesToRun) which isnt much use to me. The service has a timer which sets off every 30 seconds and will run the code in the timer event.

My question is ... is there a way of stepping through the code using the debugger in such a scenario. Do I need to have some debug specific code already in my codebase so that when a debugger attaches it will take me to a place in the code from where i can step through the code?

Thanks, Andrew.

2

2 Answers

0
votes

There are several ways to debug your developed remote application or windows service. If you were in your machine(local) that would be simple to debug.

System.Diagnostics.Debugger.Launch();

But as you are in different machine it depends how your both Machines are connected. Which means you have some limitations on debugging remote application/services.

A Quick search gave me the following result that seemed helpful to me for you,

You can use Remote Debugging Monitor that visual studio use for connecting to remote device and debugging. You can have a clear instruction here on How to: Run the Remote Debugging Monitor.

There's another tool which lets you debug remote application's after a proper setup. But it has some limitations or conditions that you must abide by.

Here is the tool named Remote Tool, you can find a detailed setup process from MSDN here on How to: Set Up Remote Debugging.

It has been clearly quoted there about the prerequisites for using this tool. But still I'm rephrasing those again for quick reviewers.

Prerequisites to use Remote Tool for Visual Studio

    To debug on a remote device:

  • The remote device and the Visual Studio computer must be connected over a network or connected directly through an Ethernet cable. Debugging over the internet is not supported.

  • The remote device must be running the Remote Tools for Visual Studio 2012.

  • You must be an administrator to install the remote tools on the remote device. To communicate with the remote tools, you must have user access to the remote device.

Feel free to share if you get to a better and working solution.

0
votes

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

The solution is simple (It always is once you know it).

Ensure that you are running the same code on the target machine as you have open in Visual Studio. It has to be the same assembly and version else the debugger will not hit your breakpoints. Ensure you have your breakpoints setup where you want the debugger to break execution. Then attach to the target machine process and wait for the timer to kick in and run the process where you breakpoint is set.

Hope this helps.

Andrew.