How to debug windows service which fails in Init() method
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 ?
you can programatically attach the debugger as the first line in the function:
Debugger.Launch ();
after adding the using statement:
using System.Diagnostics;
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.
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.
精彩评论