Error 1053 the service did not respond to the start or control request in a timely fashion [Fix]

Error 1053 the service did not respond to the start or control request in a timely fashion [Fix]

What is Error 1053: the service did not respond to the start or control request in a timely fashion

The 'Error 1053: the service did not respond to the start or control request in a timely fashion' occurs when a windows service tries to start the service and fails to start.

Why am I writing about this error?
Because this error happened to me when I wrote a microservice using C# .net 5 and this was required to be run on a windows operating as a windows service.

After creating my application and tested it before turning it into a windows service, I was happy that the application passed all tests and was happy with it. Then I created the windows service for this application. Great the service has installed locally for the final check. Opened 'Services' window and found my service and clicked 'Start'.

After about 3 seconds.  'Error 1053: the service did not respond to the start or control request in a timely fashion'. Oh no, this was the first time I had ever seen this issue.

Error 1053 the service did not respond to the start or control request in a timely fashion

Research the Error

Deciding to consult professor Google and searched a number of articles, while all of them gave the same solutions. None of which worked for me in this instance.

Some of the solutions suggested was:

  • Make sure operating system was updated and all software is up to date.
  • Manually add/update ServicesPipeTimeout value in order to increase the timeout time.
  • Scan filesystem for any errors.
  • Change the ownership of the application.

These were all checked an to no avail none of these worked for me. That isn't to say that they wont work for you. All I can do is show you what the issue was within my application, why it happened and how to fix it.

Research Windows Services

After researching the error and it came to nothing, I then decided to read up on Windows Services just in case I have missed something and I couldn't think of what else to do.

Something stood out to me. That was the path that Windows Services uses. The referenced path is 'C:\Windows\System32', at first I thought that's interesting, and thought nothing more of it. Initially I thought this was another dead end.

Error 1053 the service did not respond Fix

After not getting anywhere and trying numerous attempts to fix the issue as described on other sites. I then decided to go back to the drawing board and look over the code to see if there was something silly in the code that would stop the application running as a Windows Service.

Initially I assumed this was going to fall short once again as the application runs and works as it should, but not as a service. Then right there, it was seemed like it was staring in my face. When the application start it reads from a file and loads the data into memory.

The part of the code was:

System.IO.Directory.GetCurrentDirectory()

That was the issue, 'GetCurrentDirectory()' points to the windows service path which is 'C:\Windows\System32' and the application was not installed in this location. It became obvious to me that the error was due to the application trying to read from a file that didn't exist in that location.

After noticing this code, I then decided to try a simple experiment. I copied the json file into the location 'C:\Windows\System32' and started the service again.

Great that worked! and the application is running as it is should after a few checks. So now I know what the issue is and how to fix it, but there was another issue, I don't really want to be copying files from the install folder to the 'System32' path either manual or via script.

I now went back to the code and made a simple change. This simple change was to change this part of code from:

System.IO.Directory.GetCurrentDirectory()

to

AppDomain.CurrentDomain.BaseDirectory

To sum up why this worked nicely is because 'System.IO.Directory.GetCurrentDirectory()' points to 'C:\Windows\System32' which is the default windows service path and 'Domain.CurrentDomain.BaseDirectory' points to the folder the application folder which contains the applications '.exe'  file to run the application.

After making this change and uninstalling the app along with the service, and reinstalling it with the new code fix. It worked Perfectly without having to copy over any files from the applications folder.

 

Thanks for reading and hope this has been of some help.

Please feel free to comment if this has been useful.

 

That Developer Guy

Website:

Leave a Reply

Your email address will not be published. Required fields are marked *

13 − eleven =

Copyright © 2024 | Powered by WordPress | ConsultStreet theme by ThemeArile