OnStart() not being called. The service process could not connect to the service controller. Works manually, and on other machines

StackOverflow https://stackoverflow.com/questions/22261594

  •  11-06-2023
  •  | 
  •  

Question

I have a c# application that runs as a service and starts automatically. This service starts fine if you manually start it, but fails with this error (The service process could not connect to the service controller) in the Event Viewer on one particular Windows Server 2008 R2. I tried it on a 2nd Windows Server 2008 R2 VM and it started up automatically fine. What specifically causes this error?

This service has no dependencies, the correct permissions, and simply reads a tiny config file, and starts a thread so it won't be taking longer than 30 seconds as this post alludes to http://social.msdn.microsoft.com/Forums/en-US/dc177c75-b41b-4ff7-ae67-9ad60919e507/my-windows-service-is-not-starting-when-the-system-boots-up-even-though-it-is-set-to-automatic?forum=netfxbcl.

I have a debug statement as the first line of OnStart() that never outputs to the log file (I'm using Log4Net). I have a log statement in the Main() before ServiceBase.Run() gets called which is outputting to my log file, so I know logging is working.

Was it helpful?

Solution

I randomly stumbled upon this solution here: Why can't I install my service (runtime newer than loaded runtime)?

This solved my problem:

Here's what I had to do:

Right-click the service project in Visual Studio
go to "Properties"
Set "Startup object" to the name of the service (it had been set to> the value "(Not Set)").
Save.
Build Try to install again.

It works! Yay! We can all go home!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top