title: How to debug the .NET Windows Service OnStart method?
body: <p>I have code written in .NET that only fails when installed as a Windows service. The failure doesn't allow the service to even start. I can't figure out how I can step into the OnStart method.</p>
  
  <p><em><a href="http://msdn.microsoft.com/en-us/library/7a50syb3%28VS.80%29.aspx" rel="noreferrer">How to: Debug Windows Service Applications</a></em> gives a tantalizing clue:</p>
  
  <blockquote>
    <p>Attaching to the service's process allows you to debug most but not all of the service's code; for example, because the service has already been started, you cannot debug the code in the service's OnStart method this way, or the code in the Main method that is used to load the service. <strong>One way to work around this is to create a temporary second service in your service application that exists only to aid in debugging. You can install both services, and then start this "dummy" service to load the service process.</strong> Once the temporary service has started the process, you can then use the Debug menu in Visual Studio to attach to the service process. </p>
  </blockquote>
  
  <p>However, I'm not clear how it is exactly that you are supposed to create the dummy service to load the service process.</p>