views:

122

answers:

2

Hi,

I need to debug a class library project that is provided to the main project (an ASP .NET website) as a DLL. For example, I need to put some breakpoints in order to check what's happening during the execution. I tried this : http://msdn.microsoft.com/en-us/library/605a12zt.aspx, unfortunately it didn't work...

Any idea?

Thanks

[EDIT] Yes I have the source code!

+4  A: 

If you have the source code, and the .pdb files in your BIN directory, then you can debug through that code. You will need to enable external code debugging however in Visual Studio.

You need to uncheck the "Enable Just My Code" Option.

Tools --> Options --> Debugging --> "Enable Just My Code"

NOTE: This will only work for .Net assemblies

Josh
But how to debug through the code?
Amokrane
If you have the PDB files and the source files, then all you need to do is set a breakpoint somewhere in your code that calls into the external assembly. Visual Studio will automatically pick up the symbols and load them, allowing you to step into the code. If you don't have source files then there are programs that can rebuild a representation of the code from the PDB. If you don't have the .pdb files, then things get much more difficult.
Josh
@Amokrane: you will have to step into the code. Place a debugger into your code on a place before you call some methods from the DLL. Step into the method by pressing F11.
Marek
@Josh Where is this pdb file located? Inside the debug directory?@Marek When I do that it tells me: There is no source code available for the current location
Amokrane
Turns out I have them. But stepping through the code is impossible :(
Amokrane
As long as the PDB files are located right next to your assembly in the debug folder, it should load the symbols. If this doesn't happen then you can load them manually while debugging by going to Debug > Windows > Modules ---- Right click on the DLL and select Load Symbols From > File Path
Josh
Thanks Josh it's working ;)
Amokrane
+2  A: 

Is this what you're looking for? [Full disclosure: Yes, this is my personal web site]

http://www.gowland.ca/debugging-dlls-in-c (see #2 in the list)

EDIT:

With method #1, you can't watch variables.

With method #2, step #2, if you can't open the project in the same VS instance, you can run the binary of the project (that is, run it outside of VS, but make sure you run the debug version.) and attach the VS debugger to it (Debug -> Attach to Process).

Here are the steps for method #2 so no one has to follow the link:

Attaching a using process to the DLL project This involved hooking the VS debugger into a running process.

  1. Open the DLL project in VS.
  2. Run an application that uses the DLL. This application can't be run from another instance of VS since the process will already have a debugger attached to it.
  3. From here you can add break points and step through the DLL code loaded in VS (although the break point will appear disabled the same as in method 1).
Robert Gowland
This is EXACTLY what I was looking for! Awesome tips. Thank you!
Amokrane
Question please. I've tried the #1 and it showed me the stack trace but how can I do if I want to watch my variables? I didn't understand the #2. How can I run the project that uses the DLL in the same instance of visual studio where the DLL project is loaded ?
Amokrane
@Amokrane, see edit.
Robert Gowland
Ok. But I have an ASP .NET project so there is no binary file!
Amokrane
@Amokrane, I have no experience with ASP, but there must be some executable calling the DLLs. Can you attach to that and see what happens?
Robert Gowland