ZipionLive ZipionLive - 1 month ago 13
C# Question

InvalidOperationException on Windows Service installation

I have a windows service app I developed some months ago, and which ran flawlessly so far on a distant Windows Server 2012. But after a minor update, I had to reinstall it on the server and now, every time I try to run InstallUtil on this server, I get an error. Here's the full command line dialog :


Installing assembly 'c:\Program Files\My Company\MyServiceApp\MyServiceApp.exe'.
Affected parameters are:


logtoconsole =

assemblypath = c:\Program Files\My Company\MyServiceApp\MyServiceApp.exe

logfile = c:\Program Files\My Company\MyServiceApp\MyServiceApp.InstallLog


Installing service SendHistoryService...

Service SendHistoryService has been successfully installed.

Creating EventLog source SendHistoryService in log Application...

An exception occurred in the OnAfterInstall event handler of System.ServiceProcess.ServiceInstaller.

System.InvalidOperationException: Cannot start service SendHistoryService on computer '.'.

The inner exception System.ComponentModel.Win32Exception was thrown with the following error message: The service did not respond to the start or control request in a timely fashion.

Rolling back assembly 'c:\Program Files\My Company\MyServiceApp\MyServiceApp.exe'.

Affected parameters are:


logtoconsole =

assemblypath = c:\Program Files\My Company\MyServiceApp\MyServiceApp.exe

logfile = c:\Program Files\My Company\MyServiceApp\MyServiceApp.InstallLog


Restoring event log to the previous state for source SendHistoryService.

Service SendHistoryService is being removed from the system...

Service SendHistoryService was successfully removed from the system.


Note that the service installer still runs perfectly on my local machine (W8.1). The installer actually contains two separate services, called "SendHistoryService" and "GeneratorService" but, as you can see, the installer fails while trying the install the first of them. If it has any relevance, the process gets stuck for about 30 seconds on the following line :

Creating EventLog source SendHistoryService in log Application...


Of course, the first thing I checked is the OnAfterInstall event handler, but nothing wrong seems to happen there :

[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller() { InitializeComponent(); }

private void ServiceProcessInstaller_AfterInstall(object sender, InstallEventArgs e) { }

private void GeneratorServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
{
using (var sc = new ServiceController(GeneratorServiceInstaller.ServiceName))
sc.Start();
}

private void SendHistoryServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
{
using (var sc = new ServiceController(SendHistoryServiceInstaller.ServiceName))
sc.Start();
}
}


I really can't make sense of what's happening here. Any clue ?

EDIT : I tried commenting the lines that start the services in the ProjectInstaller class. Now the installation runs normally, but when I try to start the services, it fails and I get the following error message :


Windows could not start the SendHistoryService service on Local Computer.

Error 1053: The service did not respond to the start or control request in a timely fashion.

Answer

Finally, my problem was caused by a connection string issue, which I took some time to find as the error message is as little explicit as possible. What is surprising here is that the service reached a timeout instead of throwing an exception. And from what I've read during online searches, this error message can have many different possible causes.

Comments