安装程序的 OnAfterInstall 事件处理程序发生异常

An exception occurred in the OnAfterInstall event handler of the Installer

我已经创建了一个 windows 服务,我正试图将其部署到服务器上。

并尝试以管理员角色使用命令提示符安装它。

安装人员:

[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
    public ProjectInstaller()
    {
        InitializeComponent();
    }

    protected override void OnAfterInstall(IDictionary savedState)
    {
        base.OnAfterInstall(savedState);

        //The following code starts the services after it is installed.
        using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName))
        {
            serviceController.Start();
        }
    }

    private void serviceProcessInstaller1_AfterInstall(object sender, InstallEventArgs e)
    {
        //this.serviceProcessInstaller1.Account = ServiceAccount.LocalSystem;
    }

    private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
    {

    }
}

它抛出错误,

an exception occurred in the onafterinstall event handler

还有,

System.InvaldiOperationException: Cannot start service on Computer. etc.

有什么及时的解决方案吗?
类似帖子:Post-1, Post-2

有关服务 "not responding in a timely manner" 的错误消息表明您的服务在某种程度上出现故障。启动机制不是一劳永逸的设计,它更像是对服务启动代码的调用。该服务应(及时)退出其启动代码以指示其 运行。您的启动代码很可能在内联中做了太多工作,而不是仅仅进行基本初始化,然后实例化一个线程来完成服务的主要工作,或者它挂在某个地方。