Can't debug Windows Service -"attach to process"
Solution 1
You must do the following:
- Open your solution in Visual Studio Administrator mode.
- Make sure your service is running.
- Open the "Attach to process window"
- Make sure both checkboxes are checked (all users, all sessions).
- Find the name of your executable in the list.
If the above doesn't work, you will need to provide some additional details about your setup. :-)
Solution 2
You may add somewhere in service, for example in OnStart method this code:
#if DEBUG
System.Diagnostics.Debugger.Launch();
#endif
On service start, you will get a prompt dialog to debug process. Don't forget to build in Debug mode and switch to Release in production
Comments
-
boruchsiper over 3 years
Microsoft instructions state the following
In Visual Studio, choose Attach to Process from the Debug menu.
The Processes dialog box appears.
Click Show system processes.
In the Available Processes section, click the process for your service, and then click Attach.
However, I don't see the "Show system processes." option. I've tried checking off the other options but my service doesn't show up in the list.
Yes, I've installed and started the services and can see it in the in service manager.
I'm also aware that It's not possible to debug onstart. However, I have a continuous loop running.
-
boruchsiper over 11 yearsI started VS as administrtor but unfortunately I still couldn't see the service in the list.
-
adnan over 8 yearsthis works me to debug the function in service start, i just open the solution in visual studio to run as Administrator. then i add System.Diagnostics.Debugger.Launch(); in Service Start function. thanks @Yuriy