8

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?

3 Answers 3

9

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

Sign up to request clarification or add additional context in comments.

1 Comment

Use windows event log... EventLog.WriteEntry(String.Format("WcfServiceHostTest \n Exception Message: {0}\nTrace: {1}", ex.Message, ex.StackTrace), EventLogEntryType.Error);
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.

1 Comment

This ExitCode will appear both in net start output, or starting it from the Services MMC window.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.