Can't debug windows service.

M

Manohar

I have created a windows service which works quite good. I am
executing a stored procedure and check the status of few data. After
installing, it works good. But, when I tried to debug the windows
service by attaching the process from VS 2005, all the breakpoints
which I set turned to the infamouse message:

"The breakpoint will not currently be hit. No symbols have been
loaded for this document."

1. I have built the service in debug mode.
2. pdb file and the exe file have the same timestamp.

Can somebody help me out in this?

Thanks
 
M

Marc Gravell

I find the easiest way to debug a service is to develop it as a
console exe with an optional command-line switch (such as -c) which
(if present) makes the entry-point [aka Main()] run the actual code,
rather than the usual ServiceBase.Run(...)

This way, you can debug directly in VS2005 by specifying the debug
command-line and pressing "play". For serious development this is a
lot quicker than the build cycle for a one-line change in a genuine
service (NET STOP, build, NET START, attach debugger... yeuch)

Note that this helps with general functional debugging, but there are
some subtle nuances related to security etc that are different when
running as a bona-fide service. Once it works in console mode, you
also need to verify that it works correctly as a service; you
shouldn't have too much trouble.

Marc
 
G

Guest

Make sure you place the debug files in the same location where your service
is registered at.

Also, what i do to make debugging services somewhat simplier is on the
OnStart() event handler, I place a

Debugger.Launch();

statement. What this does is that it generates the "An uhandled exception
caught, do you want to Debug?" window. From that Window I choose the
instance of Visual Studio that has my opened solution (assuming your VS
Solution is opened). Then my breakpoint hits, even breakpoints in the
OnStart() event handler.
 

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