How to Identify Windows Service Start Failure?

Identifying the Service 

Once our Windows Service is successfully installed in the system and added to the Services list. Its time to get it running. For that we can open the Service Explorer by running the command services.msc in the Run Window. We can see the service that is added as shown below:

Windows Service

We can start the service by right-click on the service to invoke the context menu for the service which contains options such as start, stop pause etc. We can  click on the start option to start the service.

Identifying the Service Errors

If the service fails to start no need to worry we can figure the actual reason for the failure by using the Event Viewer Tool from Windows. This tool will list the events which occurred when the system is in ON state. There we can search for some errors thrown by our service, sample is shown below:

Event Viewer

As its clearly shown in the figure above we can see the error thrown along with the call stack giving an indication of the potential reason for the failure.

In this case the call stack says that the exception occurred primarily due to the Address Already in Use Exception. Which means that the address to which our service is bound to especially the port number is already in use and is not free.

Windows Event Viewer Debug

Therefore in this case we can go to the "App.Config" file for the service where we have written the binding information and change the port to some port which is open. Service starts up after doing this change.

Suggested Read : Creating Windows Service

In this case it was evident from the call stack regarding the reason for the failure but in certain situation it may not be very evident therefore we have to rely on getting the dump file generated by the application and try to analyze the dump file using windbg for any clue.

Once the service is successfully started you can see the entry in the Event Viewer regarding the same.

Comments

Popular posts from this blog

Creating RESTful Minimal WebAPI in .Net 6 in an Easy Manner! | FastEndpoints

Step By Step Guide to Detect Heap Corruption in Windows Easily

How to dynamically add Properties in C# .NET?