How to debug a referenced dll (having pdb)

C#Visual StudioVisual Studio-2008Visual Studio-2005

C# Problem Overview


I have two solutions in my workspace, say A and B.

Solution A is an older project which I finished coding some time ago. In solution B, I need to use some classes from Solution A. To do so, I add a reference to the dll of one of the projects in solution A.

The problem is when I try to debug. I want to be able to step into A's code as well. Visual studio is not able to load the code for these classes ("There is no source code available for the current location.") and I can only view the disassembly, which is not useful.

The only way I know to debug classes from solution A is by running solution B, detach all processes (in the Debug menu item) and attach the process from solution A.

However, this is very inconvenient and I can only debug A OR B at once.

Is there a way to allow stepping into the code of referenced dlls (for which I do have the source code)?


Solution: My mistake was that I thought that a project can only be part of a single solution. In fact, a project can be part of any number of solutions.
When you need to reference the old project, you should simply add the project to the solution. This is done by right clicking the new solution in the Solution Explorer > Add > Existing Project.
Then, you'll be able to add the project reference. As others wrote, you should probably completely avoid using dll references to your own code (or other code you might need to change and debug).

A very good reference to how solutions should be designed can be found in MSDN.

C# Solutions


Solution 1 - C#

If you have a project reference, it should work immediately.

If it is a file (dll) reference, you need the debugging symbols (the "pdb" file) to be in the same folder as the dll. Check that your projects are generating debug symbols (project properties => Build => Advanced => Output / Debug Info = full); and if you have copied the dll, put the pdb with it.

You can also load symbols directly in the IDE if you don't want to copy any files, but it is more work.

The easiest option is to use project references!

Solution 2 - C#

I had the same issue. He is what I found:

  1. make sure all projects are using the same Framework (this is crucial!)

  2. in Tools/Options>Debugging>General make sure "Enable Just My Code (Managed Only) is NOT ticked

  3. in Tools/Options>Debugging>Symbols clear any cached symbols, untick and delete all folder locations under the "Symbols file (.pdb) locations" listbox except the default "Microsoft Symbol Servers" but still untick it too. Also delete any static paths in the "Cache symbols in this directory" textbox. Click the "Empty Symbols Cache" button. Finally make sure the "Only specified modules" radio button is ticked.

  4. in the Build/Configuration Manager menu for all projects make sure the configuration is in Debug mode.

Solution 3 - C#

Step 1: Go to Tools-->Option-->Debugging

Step 2: Uncheck Enable Just My Code

Step 3: Uncheck Require source file exactly match with original Version

Step 4: Uncheck Step over Properties and Operators

Step 5: Go to Project properties-->Debug

Step 6: Check Enable native code debugging

Solution 4 - C#

Another point to keep in mind, be sure the referenced dlls are not installed in the GAC. After testing, I installed my dlls into the GAC to do system level testing. Later, when I had to debug my code again, I couldn't step into the referenced assemblies until I deleted them from the GAC.

Solution 5 - C#

I had the *.pdb files in the same folder and used the options from Arindam, but it still didn't work. Turns out I needed to enable Enable native code debugging which can be found under Project properties > Debug.

Solution 6 - C#

When you want to set a breakpoint in source code of a referenced dll, first make sure that you have a pdb file available for it. Then you can just open the related source code file and set a breakpoint over there. The source file does not need to be part of your solution. As explained in https://stackoverflow.com/questions/2617659/how-can-i-set-a-breakpoint-in-referenced-code-in-visual-studio

You can review your breakpoints through the breakpoints window, available via Debug -> Windows -> Breakpoints.

This approach has the benefit that you are not required to add an existing project to your solution just for debugging purposes as leaving it out has saved me a lot of build time. Evidently, building a solution with only one project in it is much faster than building a solution with lots of them.

Solution 7 - C#

Make sure your DLL is not registered in the GAC. Visual Studio will use the version in the GAC and it will probably have no debugging information.

Solution 8 - C#

I don't want to include an external class library project in some of my solutions, so I step into assemblies that I consume in a different way.

My solutions have a "Common Assemblies" directory that contains my own DLLs from other projects. The DLLs that I reference also have their accompanying PDB files for debugging.

In order to debug and set breakpoints, I set a breakpoint in the consuming application's source where I'm calling a method or constructor from the assembly and then step INTO (F11) the method/constructor call.

The debugger will load the assembly's source file in VS and new breakpoints inside of the assembly can be set at that point.

It's not straight forward but works if you don't want to include a new project reference and simply want to reference a shared assembly instead.

Solution 9 - C#

The most straigh forward way I found using VisualStudio 2019 to debug an external library to which you are referencing in NuGet, is by taking the following steps:

  1. Tools > Options > Debugging > General > Untick 'Enable Just My Code'

  2. Go to Assembly Explorer > Open from NuGet Packages Cache List item

  3. Type the NuGet package name you want to debug in the search field & click 'OK' enter image description here

  4. From the Assembly Explorer, right-click on the assembly imported and select 'Generate Pdb' enter image description here

  5. Select a custom path where you want to save the .PDB file and the framework you want this to be generated for

enter image description here

  1. Copy the .PDB file from the folder generated to your Debug folder and you can now set breakpoints on this assembly's library code

Solution 10 - C#

The following solution worked for me. It involves copy pasting the .dll and .pdb files properly from project A to B: https://stackoverflow.com/a/16546777/5351410

Solution 11 - C#

It must work. I used to debug a .exe file and a dll at the same time ! What I suggest is

  1. Include the path of the dll in your B project,
  2. Then compile in debug your A project
  3. Control that the path points on the A dll and de pdb file.... 4)After that you start in debug the B project and if all is ok, you will be able to debug in both projects !

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEladView Question on Stackoverflow
Solution 1 - C#Marc GravellView Answer on Stackoverflow
Solution 2 - C#scott_fView Answer on Stackoverflow
Solution 3 - C#Arindam DharView Answer on Stackoverflow
Solution 4 - C#KevinHouView Answer on Stackoverflow
Solution 5 - C#RoaldView Answer on Stackoverflow
Solution 6 - C#Carl in 't VeldView Answer on Stackoverflow
Solution 7 - C#Guillermo PrandiView Answer on Stackoverflow
Solution 8 - C#Jeff LaFayView Answer on Stackoverflow
Solution 9 - C#magicode118View Answer on Stackoverflow
Solution 10 - C#YoniWitzView Answer on Stackoverflow
Solution 11 - C#MatthieuView Answer on Stackoverflow