74

I am trying to debug a project that has a reference to a DLL that I added, the DLL is stored in an external directory and I just added a reference. Now of course I can debug my project but the line that calls a method on my other dll I can't step into it, i.e. F12.

One way I was able to do this was to add my project (dll) as an existing project to my solution and replace the referenced dll to use the attached project rather than a file on disk.

But what a mess, I am sure there is a cleaner way?

I seem to remember if I copy some PDB files or something but i can't remember. And Do i need to open 2 copies of visual studio, 1 for my main project and 1 for my referenced DLL??

Mahdi
  • 9,247
  • 9
  • 53
  • 74
Martin
  • 23,844
  • 55
  • 201
  • 327
  • Try copying the PDB files over. I believe that will work similarly to the way references to the microsoft symbol servers work. – P.Brian.Mackey May 14 '13 at 15:09

5 Answers5

83

Rebuild the second solution in Debug mode on your own machine (so that file paths in that PDB are specific to your machine).

Copy both the .DLL and .PDB files to your references folder. Visual Studio will pick up the .PDB file automatically and use the file paths to show source.

You can also use Symbol Server and Source Server to achieve this when the referenced assembly is built elsewhere: http://msdn.microsoft.com/en-us/library/vstudio/ms241613.aspx

Liam
  • 27,717
  • 28
  • 128
  • 190
Knaģis
  • 20,827
  • 7
  • 66
  • 80
  • 14
    How do you add break points into the DLL's code if it is not possible for you to step right into the code through a direct method call? – Krisztián Balla Jan 13 '14 at 13:40
  • Thats a great answer. I was wondering why I couldn't dubug to DLL !!! I missed to copy the .PDB file . Once it is copied, it worked fine :) @Knaģis – Sarath Subramanian Jan 27 '15 at 09:48
  • 2
    @JennyO'Reilly you could compile a `System.Diagnostics.Debugger.Break()` (https://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break(v=vs.110).aspx) method call into your solution. Obviously be careful that this doesn't end up in production code (maybe use a `#if DEBUG` precompile statements) – Liam Sep 04 '15 at 13:50
  • 6
    @Liam Or you can just add a breakpoint in the cs file if you open it in the same visual studio instance. – Maarten Sep 04 '15 at 14:15
  • This worked for me! Here is where I don't mind having duplicate questions in SO. This question did not have the right answer for me: http://stackoverflow.com/questions/1130417/how-to-debug-a-referenced-dll – Jess Nov 09 '15 at 15:13
  • this was exactly what I needed, I went the .PDB route and my issue specifically was no the getter of a property, that property had roots in the DLL code, so I opened up the code from the place we exported the DLL and set break points. Viola! – Eric Bishard May 20 '16 at 18:15
  • Great answer, but **restart VS is mandatory!** I spend few hours on that... – p__d May 24 '17 at 08:02
18

I got the solution by doing the below

Try disabling Just My Code (JMC).

Tools -> Options -> Debugger Uncheck "Enable Just my Code"

Dilip Jangid
  • 754
  • 1
  • 10
  • 20
1

I had same problem which I resolved by cleaning and rebuilding the solution . It will correct references in .pdb files to locate and hit the break point in second project.

Aamol
  • 1,149
  • 1
  • 15
  • 23
0

When you do a Debug build, all of the dll and pdb files are established in the host project. So there should be no need to copy files manually.

Right-Click on the Solution, select Add/Existing Project... Navigate to the Class lib folder and select the proj file (e.g. myproj.csproj). The files are not copied, just referenced and you can open the source for the class in the IDE and set breakpoints in the normal way and it just works.

Cool Blue
  • 6,438
  • 6
  • 29
  • 68
0

Visual Studio 2022 added a new top-level node: External Sources to solution explorer, which you will find while in debug mode. You can look at all the loaded dlls from there. You can also look at the loaded modules from Debug -> Windows -> Modules in debug mode. From there, right click on your desired dll, and click open file location, and then copy the pdb file to that location. This should allow you to step into any methods of the external dll. Reference: https://devblogs.microsoft.com/visualstudio/debugging-external-sources-with-visual-studio/

Rayhan
  • 16
  • 3
  • Hi Rayhan, I am trying to load symbols for one of the dll. while doing load symbols, its opening the project folder asking to open the pdb file. But I dont find the relevant one. Can you please guide ? – Bhargavi Apr 29 '23 at 16:40