Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET - How to debug a DLL?

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 How to: Debug from a DLL Project, unfortunately it didn't work...

How can I do it?

PS: I have the source code!

like image 913
Amokrane Chentir Avatar asked Apr 12 '10 13:04

Amokrane Chentir


2 Answers

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

You need to uncheck the "Enable Just My Code" option: menu Tools --> Options --> Debugging --> Enable Just My Code

NOTE: This will only work for .NET assemblies.

like image 158
Josh Avatar answered Oct 31 '22 18:10

Josh


Debugging DLLs in Visual Studio (see #2 in the list) may be what you're looking for (full disclosure: Yes, this is my personal web site).

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

  • With method #2, step #2, if you can't open the project in the same Visual Studio instance, you can run the binary of the project (that is, run it outside of Visual Studio, but make sure you run the debug version.) and attach the Visual Studio debugger to it (menu 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 Visual Studio debugger into a running process.

  1. Open the DLL project in Visual Studio.
  2. Run an application that uses the DLL. This application can't be run from another instance of Visual Studio since the process will already have a debugger attached to it.
  3. From here you can add breakpoints and step through the DLL code loaded in Visual Studio (although the breakpoint will appear disabled the same as in method 1).
like image 23
Robert Gowland Avatar answered Oct 31 '22 18:10

Robert Gowland