【问题标题】:InvalidOperationException on Windows Service installationWindows 服务安装时出现 InvalidOperationException
【发布时间】:2016-03-14 14:23:40
【问题描述】:

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

正在安装程序集“c:\Program Files\My Company\MyServiceApp\MyServiceApp.exe”。 受影响的参数有:

登录控制台 =
程序集路径 = c:\Program Files\My Company\MyServiceApp\MyServiceApp.exe
日志文件 = c:\Program Files\My Company\MyServiceApp\MyServiceApp.InstallLog

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

登录控制台 =
程序集路径 = c:\Program Files\My Company\MyServiceApp\MyServiceApp.exe
日志文件 = c:\Program Files\My Company\MyServiceApp\MyServiceApp.InstallLog

将源 SendHistoryService 的事件日志恢复到以前的状态。
服务 SendHistoryService 正在从系统中删除...
服务 SendHistoryService 已成功从系统中删除。

请注意,服务安装程序仍然可以在我的本地计算机 (W8.1) 上完美运行。安装程序实际上包含两个单独的服务,称为“SendHistoryService”和“GeneratorService”,但是,如您所见,安装程序在尝试安装第一个服务时失败。如果它有任何相关性,则该过程会在以下行卡住大约 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();
    }
}

我真的无法理解这里发生了什么。有什么线索吗?

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

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

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

【问题讨论】:

    标签: c# windows-services .net-4.5 windows-server-2012 installutil


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 2011-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-02
      相关资源
      最近更新 更多