-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Trying to build a background service with autostart in the background.
Core login was executing from OnStart - Modified code after several failure attempts to start by finally stripping out the business logic and trying to test only the service part.
Reduced to the core essentials below for repro.
Program.cs
namespace wserv
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
}
}Service1.cs
namespace wserv
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
}
protected override void OnStop()
{
}
}
}Compiles with no errors on buidserver (Winserver 2019) and install with nssm works ok.
However any attempt to run on Windows Server fails with the service not starting.
Expectation: Should run and do nothing (works on Win10) fails on Winserver
Eventlog has the folllowing error
Service cannot be started. The service process could not connect to the service controller
Fails to start on:
Win Server 2019 Datacenter (AWS) .net4.8
Win Server 2016 Standard (VMWare) .net4.8
Works as expected:
Win10 Enterprise 22H2 .net4.8
build with .net4.8 Framework on Windows Server 2019 Datacenter.