Tutorial :how can you debug this error? The service could not be started. The service did not report an error



Question:

The service could not be started. The service did not report an error.

I encounter this error whenever I install a windows service project in the command line. It's true that there's an error in my code, but how can I find that error with this kind of error message?


Solution:1

There is an exception in your service's OnStart() method, add

 try{...}    catch(Exception ex)   {       //write to file ex.ToString();   }  

and log your exception to file


Solution:2

Add error handling block (catching UnhandledException or just try/catch block around suspected code) and log it (I use either Trace or Debug - you can view that messages with DebugView).

In order to give idea to Service Manager that there is error (just to help user) you can:

service.ExitCode = 1064; //ERROR_EXCEPTION_IN_SERVICE - just example  

Where "service" is your Service's object.


Solution:3

If you have Visual Studio installed and you're using .NET, call System.Diagnostics.Debugger.Break() in your OnStart() function. When your service starts, you'll be prompted to debug the service. Select the Visual Studio option and you'll break into the debugger where the programmatic breakpoint is. You can debug normally from there.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »