无法启动Windows服务,错误1064

sem*_*tra 5 .net c# windows service windows-10

我写了一个Windows Service在Win10上运行,在我决定对其进行一些更改之前,它运行得很好。我重写了一些逻辑,在Debug和Release配置中对其进行了测试,一切都很好。然后,我使用卸载了当前版本的服务installutil.exe /u %servicename.exe%,然后使用重新安装了该版本installutil.exe %servicename.exe%。由于某种原因,该新版本无法启动,并且因错误1064崩溃。这是完整的错误文本:

Windows could not start %servicename% service on Local Computer. Error 1064: An exception occurred in the service when handling the control request.

上次安装此服务时,遇到了一些困难,但是通过更改Log On属性很快解决了这些问题。这次,它不起作用。请帮助解决此问题。

谢谢。

更新1

这是我Main()OnStart()服务方法:

Main()

static void Main()
{
#if DEBUG
    var service = new SalesforceToJiraService();
    service.OnDebug();
    Thread.Sleep(Timeout.Infinite);
#else
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[]
    {
        new SalesforceToJiraService()
    };
     ServiceBase.Run(ServicesToRun);
#endif
}
Run Code Online (Sandbox Code Playgroud)

OnStart()

protected override void OnStart(string[] args)
{
    this.ConfigureServices();

    this.timer.Start();
    this.logger.Information("SalesforceToJira service started.");
}
Run Code Online (Sandbox Code Playgroud)

更新2

更多代码:

ConfigureServices()

protected void ConfigureServices()
{
    this.configuration = ConfigurationHelper.LoadConfiguration(ConfigurationPath);
    this.logger = ConfigurationHelper.ConfigureLogger(this.configuration.Logs.LogsPath);

    this.timer = ConfigurationHelper.ConfigureTimer(this.configuration.ProcessInterval.TotalMilliseconds,
        (sender, eventArgs) => this.ProcessCasesAsync(sender, eventArgs).GetAwaiter().GetResult());

    this.salesforceClient = new SalesforceCliClient(this.configuration.Salesforce.CliPath);

    this.jiraClient = Jira.CreateRestClient(
        this.configuration.Jira.Url,
        this.configuration.Jira.Username,
        this.configuration.Jira.Password);
}
Run Code Online (Sandbox Code Playgroud)

Newtonsoft.JSON用于反序列化JSON配置文件,Serilog日志记录,System.Timers.Timer定期事件,AtlassianSDKJira API和Salesforce CLISalesforce的一些包装。

ne1*_*10s 34

Thanks to @Siderite Zackwehdex's comment, I was able to find the full stack trace of the underlying exception in EventViewer, under:

Windows Logs\Application

In my case, my service is named "HttpDispatcher", which appears in the "Source" column in the top pane.

I could see immediately it was due to a dependency issue where my .NET 4.7.2 project was not pulling across my .NET Standard references. (That ol' chestnut).

事件查看器:Windows 日志/应用程序

  • 尽管我看到很多答案都在谈论他们所面临的导致此问题的具体问题,但这是唯一一篇谈论如何解决问题的帖子:) (2认同)