Monday, August 12, 2013

Windows Service Debug Installation

This morning I was faced with the issue of debugging a Windows Service installation. It was driving me crazy, as I did not know a easy way to run the installation through Visual Studio debugger.

After reading through the logs of the installation I could see that there was an exception being thrown in the BeforeInstallation() override method but the rest of the information was just vague enough to not be able to quickly find the answer.

After asking my friend Google if he had ever heard of this problem I was directed to a StackOverflow post that had a similar issue. Poster Klaus had a suggestion that was all I needed. He suggested posting the below code in the area you want to debug:

Debugger.Break();

At this point you run CMD prompt, as an administrator, and install the service. The install will break but then you'll be asked to continue in debug mode and, viola, you're in.

My problem turned out to be a null reference in the context, which was easily fixed thanks to the help of debugger and Klaus. Thanks Klaus!

Stack Overflow post ref.

No comments:

Post a Comment