views:

82

answers:

3

I have a windows service which fails in Init() method and throws some exception , so only way for me to check what the error is by looking at the event log. I want to debug the windows service, but the problem is that i can attach debugger only when service is rnning, in my case it fails in Init() method only. Any idea ?

+2  A: 

you can programatically attach the debugger as the first line in the function:

Debugger.Launch ();

after adding the using statement:

using System.Diagnostics;
Sam Holder
Thanks,that helped.
Nikhil Vaghela
A: 

probably you can get the dumps of the crash using DebugDiag or windbg.

is your service C++ or C#.

Also maybe it is just a first chance exception and not really a crash. Can you provide more info on the failure.

ckv
+1  A: 

What I usually do is to have a class with a static void Main() entry point, which I can then temporarily assign in the project properties. From there, I call the same startup functions that are called when the app is run as a service.

RickNZ