如何修复Windows服务安装错误 [英] How Do I Fix Windows Service Installation Error

查看:237
本文介绍了如何修复Windows服务安装错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello House,



i一直致力于Windows服务应用程序,

 正在运行  a   transacted   installation   i   am    问题 安装       错误 消息: 



开始 安装 阶段 安装
参见 内容 < span class =code-leadattribute>
log file for C:\\\\\\\\\\\\\\\\\\\\\\ \bin\Debug\windowsservice。 exe 程序集的进度
file < span class =code-leadattribute>位于 位于 C:\\\\\\\\\\\\\\\\\\\\\\\\\ InstallLog

发生 异常 安装
系统 InvalidOperationException: Unable to create a 实例 WindowsService ProjectInstaller installer type
inner exception < span class =code-leadattribute> System 。 Reflection TargetInvocationException thrown 错误 消息: 异常 抛出 span 调用 ..
inner exception System NullReferenceException thrown error 消息: 对象 参考 set 实例 object ..

回滚 阶段 安装 leadattribute>是 开始
参见 内容 < span class =code-leadattribute>
log file for C:\\\\\\\\\\\\\\\\\\\\\\ \bin\Debug\windowsservice。 exe 程序集的进度
file < span class =code-leadattribute>位于
位于 C:\\\\\\\\\\\\\\\\\\\\\\\\\ InstallLog
发生 异常 < span class =code-leadattribute>
回滚 阶段 System 配置安装 AssemblyInstaller 安装程序
系统 InvalidOperationException: Unable to create a 实例 WindowsService ProjectInstaller installer type
inner exception < span class =code-leadattribute> System 。 Reflection TargetInvocationException thrown 错误 消息: 异常 抛出 span 调用 ..
inner exception System NullReferenceException thrown error 消息: 对象 参考 set 实例 object 的lass =code-leadattribute>
< span class =code-leadattribute>
异常 发生 回滚 阶段 安装 例外 忽略 rollback 继续但是 machine 可能 完全 恢复 initial state rollback 完成

回滚 阶段 已完成 已成功

transacted install 已完成





我的Service1.cs文件:



公共部分类OGSG:ServiceBase 
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()。DeclaringType);
定时器timer1 =新的Timer();
public OGSG()
{
InitializeComponent();
this.ServiceName =OGSG;
log4net.Config.XmlConfigurator.Configure();
if(!System.Diagnostics.EventLog.SourceExists(OGSG))
{
System.Diagnostics.EventLog.CreateEventSource(OGSG,MyOGSGLog);
}

//将我们的事件日志设置为系统创建的日志
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(应用程序已启动);
}
catch(Exception ex)
{
log.Error(ex.Message);
}

}

protected override void OnStop()
{
timer1.Enabled = false;
this.Stop();
log.Info(申请已停止);
}

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(记录更新成功!);
}
}
}
catch(Exception ex)
{
log.Error(ex.Message);
}
}
}







我的ProjectInstaller类:



 [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;

//必须与Program的构造函数中设置的
serviceInstaller.ServiceName =OGSG相同;

this.Installers.Add(processInstaller);
this.Installers.Add(serviceInstaller);
}





如果有人可以帮忙解决这个问题,我将不胜感激?

解决方案

Hello House,

i have been working on a windows service application,

Running a transacted installation. 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?

解决方案

这篇关于如何修复Windows服务安装错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆