.NET - How to debug a DLL?

I need to debug a class library project that is provided to the main project (ASP.NET website) as a DLL. For example, I need to set some breakpoints to check what happens at runtime.

I tried How to debug a DLL project , unfortunately it did not work ...

How can i do this?

PS: I have the source code!

+6
debugging dll
source share
3 answers

Debugging DLLs in Visual Studio (see No. 2 on the list) may be what you are looking for (full disclosure: Yes, this is my personal website).

  • Using method # 1, you cannot view variables.

  • Using method # 2, step # 2, if you cannot open the project in the same instance of Visual Studio, you can run the project binary (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 should follow the link:

Attaching the use process to a DLL project. This is due to the Visual Studio debugger connecting to the running process.

  • Open the DLL project in Visual Studio.
  • Launch the application using the DLL. This application cannot be started from another instance of Visual Studio because the process will already have a debugger attached to it.
  • Here you can add breakpoints and go through the DLL code loaded in Visual Studio (although the breakpoint will be disabled in the same way as in method 1).
+3
source share

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

You need to uncheck the box β€œInclude only my code”: Tools β†’ Options β†’ Debugging β†’ Include only my code

NOTE: This will only work for .NET assemblies.

+8
source share

When you create a class library project, a .pdb file is created in the Debug or Release folder of this class library. These two files refer to the ASP.NET project when you right-click and select the "Add Link" option and point to the DLL file of the class library project.

0
source share

All Articles