When I start to installing using installutil it gives me following error, I have set ServiceInstaller and ServiceInstallerProcess,
System.InvalidOperationException: Installation failed due to the absence of a ServiceProcessInstaller. The ServiceProcessInstaller must either be the containing installer, or it must be present in the Installers collection on the same installer as the ServiceInstaller.
Any ideas on how to fix the problem?
I had the same problem with the Installer and found that in the [YourInstallerClassName].Designer.cs at InitializeComponent() method, the dfault generated code is Missing add the ServiceProcessInstaller
//
// [YourInstallerClassName]
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceInstaller1});
Just add your ServiceProcessInstaller in my case its:
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1, //--> Missing
this.serviceInstaller1});
and the Setup project works.
Usually, this means you failed to attribute your installer with RunInstaller(true). Here's an example of one I have handy that works:
namespace OnpointConnect.WindowsService
{
[RunInstaller(true)]
public partial class OnpointConnectServiceInstaller : Installer
{
private ServiceProcessInstaller processInstaller;
private ServiceInstaller serviceInstaller;
public OnpointConnectServiceInstaller()
{
InitializeComponent();
}
public override string HelpText
{
get
{
return
"/name=[service name]\nThe name to give the OnpointConnect Service. " +
"The default is OnpointConnect. Note that each instance of the service should be installed from a unique directory with its own config file and database.";
}
}
public override void Install(IDictionary stateSaver)
{
Initialize();
base.Install(stateSaver);
}
public override void Uninstall(IDictionary stateSaver)
{
Initialize();
base.Uninstall(stateSaver);
}
private void Initialize()
{
processInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();
processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller.StartType = ServiceStartMode.Manual;
string serviceName = "OnpointConnect";
if (Context.Parameters["name"] != null)
{
serviceName = Context.Parameters["name"];
}
Context.LogMessage("The service name = " + serviceName);
serviceInstaller.ServiceName = serviceName;
try
{
//stash the service name in a file for later use in the service
var writer = new StreamWriter("ServiceName.dat");
try
{
writer.WriteLine(serviceName);
}
finally
{
writer.Close();
}
Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
}
catch (Exception err)
{
Context.LogMessage("An error occured while creating configuration information for the service. The error is "
+ err.Message);
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With