How to debug a referenced dll (having pdb)
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.
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.