Debugging a service with VS.NET

D

David Evans

Hi

I have a service created in VS.NET, which I can install and run quite
happily. After teh service is running, I can attach and run the debugger.

However, if I set a breakpoint in the IDE the break point is (presumably)
hit, but after a long pause there is an error that says "Source code cannot
be found"

I have tried:
putting the .pdb file into the install direcory and Windows\System32
installing into the default bin\Debug directory that VS.NET builds in

Any help appreciated - debugging using trace is no fun...

Regards

David
 
J

José Joye

When I create a service, what I normally do is to set the default directory
where the main assembly is located.
Right at the beginning of OnStart(), I add the following:

Process pc = Process.GetCurrentProcess();
Directory.SetCurrentDirectory
(pc.MainModule.FileName.Substring(0,pc.MainModule.FileName.LastIndexOf(@"\")
));

By the way, if I remember correctly, the default directory for a Service is
the \System32 dir. Since you tried to place the PDB(s) in the \System32, I'm
not sure it will solve your particular problem.

Grive a try ;-)

José
 
D

David Evans

Jose

Thank you very much. I suspected that it was an issue like this, which is
why I copied the .pdb file to System32.

That didn't work, and your approach did.

Regards

David
 
C

Carlos Kirkconnell

Creating classes that simulate services is a much better approach for
debugging services. Tracing the processes is really time consuming while
making impossible to debug the Start and Stop Methods. Personally what I do
when debugging a service is to create a class (not dericed from ServiceBase)
that has the Start an Stop methods. This class implement the same logic as
the service. Finally I use a form with buttons to test the "service
emulation". Debugging in this way seems easier to me.
 

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