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??

1
  • Try copying the PDB files over. I believe that will work similarly to the way references to the microsoft symbol servers work. May 14, 2013 at 15:09

5 Answers 5

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

7
  • 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? Jan 13, 2014 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 Jan 27, 2015 at 9:48
  • 2
    @JennyO'Reilly you could compile a System.Diagnostics.Debugger.Break() (msdn.microsoft.com/en-us/library/…) 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 4, 2015 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 4, 2015 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: stackoverflow.com/questions/1130417/…
    – Jess
    Nov 9, 2015 at 15:13
18

I got the solution by doing the below

Try disabling Just My Code (JMC).

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

1
  • After spending an hour trying to recompile and re-reference dll's, I can't upvote this enough!
    – dhysong
    Feb 19, 2018 at 21:36
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.

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.

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/

1
  • 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 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.