Uwak Peter

Uwak Peter

  • 1.6k
  • 96
  • 6.6k

How Do I Fix Windows Service Installation Error

Jun 10 2014 8:11 AM
Hello House,
 
i have been working on a windows service application, but i am having issues installing it. below is the error message:

 
Beginning the Install phase of the installation.
See the contents of the log file for the C:\dev\WindowsService\WindowsService\bin\Debug\windowsservice.exe assembly's progress.
The file is located at C:\dev\WindowsService\WindowsService\bin\Debug\windowsservice.InstallLog.
 
An exception occurred during the Install phase.
System.InvalidOperationException: Unable to create an instance of the WindowsService.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 invocation..
The inner exception System.NullReferenceException was thrown with the following error message: Object reference not set to an instance of an object..
 
The Rollback phase of the installation is beginning.
See the contents of the log file for the C:\dev\WindowsService\WindowsService\bin\Debug\windowsservice.exe assembly's progress.
The file is located at C:\dev\WindowsService\WindowsService\bin\Debug\windowsservice.InstallLog.
An exception occurred during the Rollback phase of the System.Configuration.Install.AssemblyInstaller installer.
System.InvalidOperationException: Unable to create an instance of the WindowsService.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 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 installation. This exception will be ignored and the rollback will continue. However, the machine might not fully revert to its initial state after the rollback is complete.
 
The Rollback phase completed successfully.
 
The transacted install has completed.


My Service1.cs file:


public partial class OGSG: ServiceBase
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
        Timer timer1 = new Timer( );
        public OGSG()
        {
            InitializeComponent( ); 
            this.ServiceName = "OGSG";
            log4net.Config.XmlConfigurator.Configure( );
            if ( !System.Diagnostics.EventLog.SourceExists( "OGSG" ) )
            {
                System.Diagnostics.EventLog.CreateEventSource( "OGSG", "MyOGSGLog" );
            }
 
            //set our event log to system created log
            eventLog1.Source = "MyLogSrc";
            eventLog1.Log = "MyLog";
        }
       
        protected override void OnStart(string[] args)
        {
            try
            {
                timer1.Elapsed += new ElapsedEventHandler( timer1_Elapsed );
                timer1.Interval = 5000;
                timer1.Enabled = true;
                timer1.AutoReset = true;
                timer1.Start( );
                
                log.Info( "Application Started" );
            }
            catch ( Exception ex)
            {
                log.Error(ex.Message);
            }
 
        }
 
        protected override void OnStop()
        {
            timer1.Enabled = false;
            this.Stop( );
            log.Info( "Application Stopped" );
        }
 
        private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            DataSet ds;
            SqlDataAdapter SqlAda;
            try
            {
                using ( SqlConnection Sqlcon = new SqlConnection( ConfigurationManager.ConnectionStrings["ContentSever"].ConnectionString ) )
                {
                    using ( SqlCommand cmd = new SqlCommand( ) )
                    {
                        Sqlcon.Open( );
                        cmd.Connection = Sqlcon;
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "InsertRecord";
 
                        SqlAda = new SqlDataAdapter( cmd );
                        ds = new DataSet( );
                        SqlAda.Fill( ds );
                        log.Info("Record Updated Successfully!");
                    }
                }
            }
            catch ( Exception ex )
            {
                log.Error( ex.Message );
            }
        }
    }

My ProjectInstaller Class:

[RunInstaller( true )]
    public partial class ProjectInstaller: System.Configuration.Install.Installer
    {
        private ServiceProcessInstaller processInstaller=null;
        private 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 );
   }


Please i will appreciate if anyone could help in fixing this?