I am maintaining a Windows Service, which has a quite unfortunate bug. I can no longer debug the code because the service simply refuses to start. This is the error:
Windows could not start the MyService service on Local Computer.
Error 1053: The service did not respond to the start or control
request in a timely fashion.
I inserted some log-to-file lines in the main method and it never comes past the instantiation of my windows service. It stops right before the line
ServiceBase.Run(ServicesToRun);
So the Run method is never executed. I am guessing that it is the instantiation of MyService that fails. But how is that possible?
static void Main()
{
//this line is reached
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new MyService() //halts here
};
//this line is never executed
ServiceBase.Run(ServicesToRun);
}
reposted reply from above:
Yes, I got info in the event viewer. It was basically an unhandled exception due to the fact that I had an incorrect configuration file. The windows service is supposed to parse an XML file on instantiation, but there was a “>” sign missing, which means it wasn’t even a valid XML file. So the lesson must be to have good error handling in the constructor of a windows service. Thank you all for your help.