views:

509

answers:

4

Hi all,

I'm trying to debug a Windows Service using VS2008 on Win7 64-Bit. The problem I'm having is that none of my breakpoints are being hit, regardless of which build configuration I choose: x86, x64 or AnyCPU.

Using "Attach to Process" after the service has started, none of the breakpoints are hit - yet the IDE doesn't inform me that they won't be hit (by making the solid red circle and outline, for instance) - it simply seems to act as if the breakpoints weren't even there.

Can anyone point me in the right direction here?

Thanks

/Richard.

A: 

Are you running Visual Studio as an administrator (incl. launched elevated under UAC)?

Nicole Calinoiu
Yes, tried with and without.
Richard
+2  A: 

Obvious questions first...

  • Are you compiling in debug mode or release mode?
  • Are the .pdb files located where your service is installed from?
  • Are you sure the code where your breakpoints are set is actually being executed?

If none of these are issues, try inserting the following line in the constructor for your service.

System.Diagnostics.Debugger.Break();

When the service starts up, you should be prompted to choose a debugger. When the debugger opens, it'll pause at the programmatic breakpoint, and you can continue from there. I don't work with Windows 7, but I don't expect this aspect of Visual Studio 2008 has changed much from Windows XP. I use this programmatic method all the time to enter a debug session for my Windows service.

Matt Davis
Compiled in debug mode, the PDB files are located where expected, 100% sure the code where the breakpoints are set is being executed. I've used the Debugger.Break() method and that didn't work. Still won't break!
Richard
I have marked this question as the answer because, although not directly the action that led to resolution, you started me on the right track with your comment about compilation modes. Ultimately, the problem was trying to debug an application in a mixed x86/x64 solution, which apparently the IDE does not like on Win7 x64. Recompiling everything as x86 did the trick. Thanks.
Richard
Thanks for the vote. Just a note...I think you can still answer your own question and then accept that answer.
Matt Davis
A: 

I know this doesn't answer your direct question but we found this approach from Eric De Carufel to be very helpful when developing and testing Window Services.

It is non intrusive and get rid of the tedious 'attach to process' step.

The ability to put it into debug when already deployed as Windows Service is also valuable. For example to see the stack trace instead of the service just dying on you.

Philip Fourie
A: 

Running Visual Studio as an administrator fixed my problem! Thanks, Nicole!

Jie