Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Unable to create an instance of the WindowsService.ProjectInstaller installer ty
pe.
System.Reflection.TargetInvocationException: Exception has been thrown by the ta
rget of an invocation.
The inner exception System.NullReferenceException was thrown with the following
error message: Object reference not set to an instance of an object..
An exception occurred during the Rollback phase of the System.Configuration.Inst
all.AssemblyInstaller installer.
System.InvalidOperationException: Unable to create an instance of the WindowsSer
vice.ProjectInstaller installer type.
The inner exception System.Reflection.TargetInvocationException was thrown with
the following error message: Exception has been thrown by the target of an invoc
ation..
The inner exception System.NullReferenceException was thrown with the following
error message: Object reference not set to an instance of an object..
An exception occurred during the Rollback phase of the installation. This except
ion will be ignored and the rollback will continue. However, the machine might n
ot fully revert to its initial state after the rollback is complete.

The Rollback phase completed successfully.

The transacted install has completed.
The installation failed, and the rollback has been performed.


My Installer file:

C#
namespace WindowsService
{
    [RunInstaller( true )]
    public partial class ProjectInstaller: System.Configuration.Install.Installer
    {
        private readonly ServiceProcessInstaller _processInstaller=null;
        private readonly ServiceInstaller _serviceInstaller = null;

   public ProjectInstaller()
   {
       InitializeComponent( );
       _processInstaller.Account = ServiceAccount.LocalSystem;
       _processInstaller.Username = null;
       _processInstaller.Password = null;


       _serviceInstaller.DisplayName = "OGSG";
       _serviceInstaller.StartType = ServiceStartMode.Automatic;

       //must be the same as what was set in Program's constructor
       _serviceInstaller.ServiceName = "OGSG";

       this.Installers.Add( _processInstaller );
       this.Installers.Add( _serviceInstaller );
       _serviceInstaller.AfterInstall += serviceInstaller1_AfterInstall;
   }

        private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
        {
           var sc = new ServiceController( "OGSG" );
            sc.Start( );
        }
    }
}

Please does anyone know how to fix this? Thanks in advance.
Posted
Comments
Richard Deeming 17-Jun-14 12:39pm    
What's in your "InitializeComponent" method? It looks like it's not initializing the _processInstaller or _serviceInstaller fields.
Uwakpeter 18-Jun-14 3:05am    
This is the InitializeComponent method:

private void InitializeComponent()
{
this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
//
// serviceProcessInstaller1
//
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
this.serviceProcessInstaller1.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.serviceProcessInstaller1_AfterInstall);
//
// serviceInstaller1
//
this.serviceInstaller1.DisplayName = "OGSG";
this.serviceInstaller1.ServiceName = "OGSG";
this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
this.serviceInstaller1.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.serviceInstaller1_AfterInstall);
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1});

}

Use the member variables
- this.serviceProcessInstaller1
- this.serviceInstaller1
instead of
- _processInstaller
- _serviceInstaller
 
Share this answer
 
Comments
Uwakpeter 18-Jun-14 4:21am    
i commented all the codes except InitializeComponent method and it works, Please what is the difference between using InitializeComponent method and commenting InitializeComponent method and use the code. Thanks
As I suspected, the fields _processInstaller and _serviceInstaller are never initialized. That means your code is trying to set properties on a null reference, which is why you're getting a NullReferenceException.

It looks like the InitializeComponent method contains the same settings as your constructor, but using the serviceProcessInstaller1 and serviceInstaller1 fields, which are initialized. You can safely remove everything from your constructor except for the call to the InitializeComponent method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900