Currently I have the following statement in my code to allow me to debug windows services:
#If DEBUG Then
System.Diagnostics.Debugger.Launch()
#End If
I place this in the OnStart method and when I start up the service I can attach to my instance of Visual Studio. Currently I have an instance where this is failing. I have the service installed on a virtual machine and I’m running into the following error:
An unhandled exception (‘Launch for user’) occurred in
MyService.exe [376]. Just-In-Time debugging this
exception failed with the following error: Debugger could not be
started because no user is logged on.
I’ve never had a problem debugging services like this on my local machine so I’m not sure what’s going on. The user is set to log on as LocalSystem if that matters. I am logged on to the virtual machine via Administrator.
I ended up putting the following statement in the OnStart method:
This allows me to manually attach to the process in visual studio and set a break point in the while loop. Once I hit the breakpoint I manually step outside of the while loop to proceed with the rest of the application.