How to debug a referenced dll (having pdb)

205,377

Solution 1

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

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

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

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

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.

Share:
205,377

Related videos on Youtube

Elad
Author by

Elad

Fullstack JavaScript Web Developer

Updated on December 30, 2020

Comments

  • Elad
    Elad over 3 years

    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.

    • Pat
      Pat almost 12 years
      That MSDN link is a must-read for .net devs (regardless of the source control they use). I'm surprised I hadn't seen it earlier. Thanks!
    • BrainSlugs83
      BrainSlugs83 over 5 years
      New comers, if you already know about project references, and that's not an option (e.g. you need to debug a NuGet package), then ignore the accepted answer and go straight to this one: stackoverflow.com/a/26029208/398630
  • Elad
    Elad almost 15 years
    Unfurtunately, I think it is not possible to add project reference to project from another solution (correct me if I am wrong!).
  • Wilhelm
    Wilhelm almost 15 years
    Yes, you can. I use all the tiem when only one part of a library is used in a new solution.
  • Elad
    Elad almost 15 years
    Could you please explain how? When I click "add reference", the Projects tab it only shows projects from the same solution.
  • Elad
    Elad almost 15 years
    Thanks Marc! Although I am still unable to add a "project reference" to another solution, now I am able to debug the referenced solution :) The key to solving the issue, as you mentioned, is adding the dll from the original project. My mistake was adding the dll from A's <b>application</b> folder. The dll is copied to that folder when the assembly is compiled. However, the pdb file is not copied and therefore I was not able to debug.
  • user420667
    user420667 over 12 years
    @Elad I just did this. First add "existing project" to the solution. Then add a reference to the project by clicking add project reference. You can set the breakpoints in the existing project files. This is nice because the files aren't copied over.
  • Slaus
    Slaus over 9 years
    I have DLL project as a project reference but break point within are ignored.
  • Tobias81
    Tobias81 over 9 years
    I actually was able to debug a (release-)assembly today that was added as a file reference. Good for me, but how did that happen? MSVC2010, C#, (ASP).NET 4.0, referenced assembly exists as debug+release (but only release-file added to project). Would really like to clarify this.
  • user627283
    user627283 almost 9 years
    My problem was that my two projects used different .Net Frameworks : 4.0 and 4.5. Tx!
  • SnookerC
    SnookerC over 8 years
    THANK YOU! This was my issue. I can't believe I didn't figure this out :-/ I thought setting the project reference would somehow override what was installed in the GAC.
  • Morvael
    Morvael over 7 years
    Not sure if I'm just being slow today. I added the reference to the project Solution -> Add -> Existing Project. But can't find the "Add Project Reference" anywhere. However adding a reference to the debug .dll once the other project was part of the solution allowed me to step into the code.
  • Paul
    Paul about 7 years
    For me it was working one day but then the next day wasn't working (having DLLs and PDB files). Pressing the "Empty Symbol Cache" button on Tools > Options > Debugging > Symbols fixed it though.
  • DigiOz Multimedia
    DigiOz Multimedia almost 7 years
    Absolutely! This is a VERY good point. Even if you have the same version of .NET Framework, if you have code in the GAC when you try to debug it won't hit the breakpoint if the .PDB file in the GAC is different then the one in your project folder. A solution for this is to Un-GAC the DLL, build, then re-GAC the assembly.
  • Josh M.
    Josh M. over 6 years
    This only works if the external file where you placed the breakpoint matches the exact path in the PDB. (E.g. only works if you built the DLL on your machine.)
  • scott_f
    scott_f over 5 years
    1) and 4) are crucial. Don't forget to build in Debug mode and use the same framework.
  • Heriberto Lugo
    Heriberto Lugo about 5 years
    this info shouldve been included in the accepted answer. its what i was specifically looking for. thanks for sharing! +1
  • Souza
    Souza almost 5 years
    Worked for me, but only after I restart IIS service.
  • testing
    testing about 4 years
    How do you load symbols directly in the IDE?
  • Robert Massa
    Robert Massa almost 4 years
    Sounds good, except I can't find any Assembly Explorer; isn't this part of Resharper?
  • jspinella
    jspinella about 3 years