安装Windows服务时出现InvalidOperationException

本文关键字:InvalidOperationException Windows 服务 安装 | 更新日期: 2023-09-27 18:26:12

我几个月前开发了一个windows服务应用程序,到目前为止,它在遥远的windows Server 2012上运行得非常完美。但在进行了一次小更新后,我不得不在服务器上重新安装它,现在,每次我试图在这台服务器上运行InstallUtil时,我都会遇到错误。以下是完整的命令行对话框:

正在安装程序集"c:''Program Files''My Company''MyServiceApp''MyServiceApp.exe"。受影响的参数包括:

logtoconsole=
assemblypath=c:''Program Files''My Company''MyServiceApp''MyServiceApp.exe
logfile=c:''Program Files''My Company''MyServiceApp''MyServiceApp.InstallLog

正在安装服务SendHistoryService
Service SendHistoryService已成功安装
正在日志应用程序中创建EventLog源SendHistoryService
System.ServiceProcess.ServiceInstaller的OnAfterInstall事件处理程序中发生异常。
System.InvalidOperationException:无法在计算机"."上启动服务SendHistoryService
引发内部异常System.ComponentModel.Win32Exception,并返回以下错误消息:服务未及时响应启动或控制请求
正在回滚程序集"c:''Program Files''My Company''MyServiceApp''MyServiceApp.exe"。
受影响的参数包括:

logtoconsole=
assemblypath=c:''Program Files''My Company''MyServiceApp''MyServiceApp.exe
logfile=c:''Program Files''My Company''MyServiceApp''MyServiceApp.InstallLog

正在将源SendHistoryService的事件日志还原为以前的状态
正在从系统中删除Service SendHistoryService
Service SendHistoryService已成功从系统中删除。

请注意,服务安装程序仍然可以在我的本地机器(W8.1)上完美运行;SendHistoryService";以及";发电机服务";但是,正如您所看到的,安装程序在尝试安装第一个时失败了。如果它有任何相关性,该过程会在以下行停留约30秒:

Creating EventLog source SendHistoryService in log Application...

当然,我检查的第一件事是OnAfterInstall事件处理程序,但那里似乎没有发生任何错误:

[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
    public ProjectInstaller() { InitializeComponent(); }
    private void ServiceProcessInstaller_AfterInstall(object sender, InstallEventArgs e) { }
    private void GeneratorServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
    {
        using (var sc = new ServiceController(GeneratorServiceInstaller.ServiceName))
            sc.Start();
    }
    private void SendHistoryServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
    {
        using (var sc = new ServiceController(SendHistoryServiceInstaller.ServiceName))
            sc.Start();
    }
}

我真的搞不懂这里发生了什么。有线索吗?

EDIT:我试着在ProjectInstaller类中注释启动服务的行。现在安装正常运行,但当我尝试启动服务时,它失败了,我得到以下错误消息:

Windows无法在本地计算机上启动SendHistoryService服务。

错误1053:服务未及时响应启动或控制请求。

安装Windows服务时出现InvalidOperationException

最后,我的问题是由连接字符串问题引起的,我花了一些时间才找到,因为错误消息尽可能不明确。这里令人惊讶的是,服务达到了超时,而不是抛出异常。根据我在网上搜索时读到的内容,这个错误消息可能有很多不同的原因。

相关文章:
  • 没有找到相关文章