.NET Core Error 1053 the service did not respond to the start or control request in a timely fashion
Asked Answered
I

4

5

I created a Windows Service starting from my .NET Core project following this

After this, I installed correctly it on my working machine and started it.

This is my service class:

using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading.Tasks;

namespace xxx
{
    public class WindowsService
    {
        static void Main(string[] args)
        {
            System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

            using (var service = new Service())
            {
                ServiceBase.Run(service);
            }
        }
    }

    internal class Service : ServiceBase
    {
        public Service()
        {
            ServiceName = "...";
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                base.OnStart(args);
                Task.Run(() => xxxx);
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("Application", ex.ToString(), EventLogEntryType.Error);
            }
        }

        protected override void OnStop()
        {
            base.OnStop();
        }

        protected override void OnPause()
        {
            base.OnPause();
        }
    }
}

So, I copied the file and installed it also on a server. Here, when I try to start it, I get:

Error showed starting the service

After this, I start a lot of googling... for example, I tried the following steps :

Go to Start > Run > and type regedit

Navigate to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control

With the control folder selected, right click in the pane on the right and - select new DWORD Value

Name the new DWORD: ServicesPipeTimeout

Right-click ServicesPipeTimeout, and then click Modify

Click Decimal, type '180000', and then click OK

Restart the computer

The weird point here is that the voice ServicesPipeTimeout didn't exist and I created it. Comparing the server with my working machine, there are also other value not present in the server. They are:

  • ServicesPipeTimeout
  • OsBootstatPath

Here the screenshot of regedit from the server:

enter image description here

Are these relevant?

I also tried to reinstall the service, recompile my files... how can I fix this problem? The error appears immediatly, it doesn't wait any timeout!

Intend answered 28/1, 2020 at 14:31 Comment(0)
D
2

I had this problem when I switched my project to another location.

When I moved the project, I had copied the files in bin/debug folder too. The issue was resolved after I cleared the debug folder and created a new build.

See if this works!

Denim answered 18/3, 2020 at 13:18 Comment(0)
S
6

It's a bit old question but someone may find this useful.

So I had the following code in Program.cs: builder.SetBasePath(Environment.CurrentDirectory).AddJsonFile("appsettings.json")

Changed it to: builder.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)).AddJsonFile("appsettings.json")

This seemed to fix the problem for me. The problem with this error is that it is super generic. Hopefully MS will give us some log in the future.

Saxhorn answered 12/10, 2021 at 13:7 Comment(1)
this hint saved me hours of commenting out code and retestingKalvin
D
2

I had this problem when I switched my project to another location.

When I moved the project, I had copied the files in bin/debug folder too. The issue was resolved after I cleared the debug folder and created a new build.

See if this works!

Denim answered 18/3, 2020 at 13:18 Comment(0)
C
2

if you check the windows event viewer under applications it tells you what exactly is the exception that causes this error.
in my case the problem was i published the service in net6 and tried to run it on a pc with net7 installed. apparently it requires the exact major version that was used to publish the app.

Cheloid answered 7/1, 2023 at 12:20 Comment(1)
While you are correct that the exception can be found in the Windows event viewer, there is absolutely no useful information. I get two errors per attempt on a service I picked up for maintenance from a departed co-worker, I get:: 1) The xxxServiceInQuestionxxx service failed to start due to the following error: The service did not respond to the start or control request in a timely fashion. 2) A timeout was reached (30000 milliseconds) while waiting for the xxxServiceInQuestion service to connect. That tells me absolutely nothing useful.Klayman
K
0

I was having this problem. I tried several of the things in this thread, but found elsewhere that the Release build must be used, not the Debug build. I hope this helps someone else!

Klayman answered 17/9 at 21:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.