Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Installation failed due to the absence of a ServiceProcessInstaller" Problem

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?

like image 764
Furqan Misarwala Avatar asked May 04 '10 12:05

Furqan Misarwala


2 Answers

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.

like image 133
jmozko Avatar answered Oct 30 '22 12:10

jmozko


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);
            }
        }
    }
}
like image 23
Tom Cabanski Avatar answered Oct 30 '22 12:10

Tom Cabanski