How Do I Debug A Windows Service with VS.NET 2005?

T

TC

I have a service application I need to debug. I've seen a lot of
documentation which say that Visual Studio can debug a service by
"attaching a debugger" to a running service. All documentation
describes the same steps: Run the service, then choose Debug/Processes
from the menu in Visual Studio.

In my version of Visual Studio, there is no option called "Processes"
under the Debug menu. I'm using Visual Studio version 8.0.50727.762
(SP.050727-7600). Is my VS obsolete, or is the documentation obsolete?
And if the documentation is obsolete, what is the current method for
attaching a debugger to a running service?

-TC


References:

http://msdn2.microsoft.com/en-us/library/7a50syb3(VS.80).aspx
http://www.ondotnet.com/pub/a/dotnet/2003/09/02/debuggingsvcs.html
http://groups.google.com/group/micr...ages.vb/browse_thread/thread/13d937dd26a1f08c
 
H

Herfried K. Wagner [MVP]

TC said:
I have a service application I need to debug. I've seen a lot of
documentation which say that Visual Studio can debug a service by
"attaching a debugger" to a running service. All documentation
describes the same steps: Run the service, then choose Debug/Processes
from the menu in Visual Studio.

In my version of Visual Studio, there is no option called "Processes"
under the Debug menu. I'm using Visual Studio version 8.0.50727.762
(SP.050727-7600).

Which edition of VS are you using?
 
C

Chris Dunaway

I have a service application I need to debug. I've seen a lot of
documentation which say that Visual Studio can debug a service by
"attaching a debugger" to a running service. All documentation
describes the same steps: Run the service, then choose Debug/Processes
from the menu in Visual Studio.

In my version of Visual Studio, there is no option called "Processes"
under the Debug menu. I'm using Visual Studio version 8.0.50727.762
(SP.050727-7600). Is my VS obsolete, or is the documentation obsolete?
And if the documentation is obsolete, what is the current method for
attaching a debugger to a running service?

-TC

References:

http://msdn2.microsoft.com/en-us/li.../group/microsoft.public.dotnet.languages.vb/b...

Try Tools ---> Attach to Process

Chris
 
P

Phill W.

Here's alternative that I use when developing Services (once they're
deployed and running, you're stuck with Process > Attach but, until
then...).

Imports System.ServiceProcess

Namespace Zyx.Wvu.Tsr
Public Class ServiceClass
Inherits ServiceBase

' The main entry point for the process
<MTAThread()> _
Public Shared Sub Main()
If System.Diagnostics.Debugger.IsAttached Then
Dim svc As New ServiceClass
svc.OnStart( New String() {} )
MsgBox( "Service Running. Click OK to terminate..." _
, MsgBoxStyle.OKOnly Or MsgBoxStyle.Information _
, svc.ServiceName )
svc.OnStop()
Else
Dim ServicesToRun() As ServiceBase _
= New ServiceBase() { New ServiceClass }
ServiceBase.Run( ServicesToRun )
End If
End Sub
End Class
End Namespace

With this in place, you can start the service directly from within the IDE.

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top