How to debug external class library projects in visual studio?

Visual StudioDebugging

Visual Studio Problem Overview


I have a project(A) that references an assembly from an external project(B) class library that is located in another vs solution.

I have yet to understand how i can efficiently debug the class library from B while running the program from project A. Is there something I have to enable on project B such as debug info etc so I can step-into at debug time from A?

Visual Studio Solutions


Solution 1 - Visual Studio

Try disabling Just My Code (JMC).

  • Tools > Options > Debugging
  • Uncheck "Enable Just My Code"

By default the debugger tries to restrict the view of the world to code that is only contained within your solution. This is really heplful at times but when you want to debug code which is not in your solution (as is your situation) you need to disable JMC in order to see it. Otherwise the code will be treated as external and largely hidden from your view.

EDIT

When you're broken in your code try the following.

  • Debug > Windows > Modules
  • Find the DLL for the project you are interested in
  • Right Click > Load Symbols > Select the Path to the .PDB for your other project

Solution 2 - Visual Studio

Assume the path of

Project A

C:\Projects\ProjectA

Project B

C:\Projects\ProjectB

and the dll of ProjectB is in

C:\Projects\ProjectB\bin\Debug\

To debug into ProjectB from ProjectA, do the following

  1. Copy B's dll with dll's .PDB to the ProjectA's compiling directory.
  2. Now debug ProjectA. When code reaches the part where you need to call dll's method or events etc while debugging, press F11 to step into the dll's code.

NOTE : DO NOT MISS TO COPY THE .PDB FILE

Solution 3 - Visual Studio

This has bugged me for some time. What I usually end up doing is rebuilding my external library using debug mode, then copy both .dll and the .pdb file to the bin of my website. This allows me to step into the libarary code.

Solution 4 - Visual Studio

I run two instances of visual studio--one for the external dll and one for the main application.
In the project properties of the external dll, set the following:

Build Events:

  • copy /y "$(TargetDir)$(TargetName).dll" "C:\<path-to-main> \bin\$(ConfigurationName)\$(TargetName).dll"

  • copy /y "$(TargetDir)$(TargetName).pdb" "C:\<path-to-main> \bin\$(ConfigurationName)\$(TargetName).pdb"

Debug:

  • Start external program: C:\<path-to-main>\bin\debug\<AppName>.exe

  • Working Directory C:\<path-to-main>\bin\debug

This way, whenever I build the external dll, it gets updated in the main application's directory. If I hit debug from the external dll's project--the main application runs, but the debugger only hits breakpoints in the external dll. If I hit debug from the main project, the main application runs with the most recently built external dll, but now the debugger only hits breakpoints in the main project.

I realize one debugger will do the job for both, but I find it easier to keep the two straight this way.

Solution 5 - Visual Studio

[according to Martin Beckett, the guy who send me this answer ]

You can debug into an external library.

In the project settings tab look for 'visual studio directories' in the 'source code' field include the path to the openCV sources. Then make sure that the .pdb files for each of the debug dll are in the same directory as the dll.

Solution 6 - Visual Studio

If you have main (project A) and external library (project B):

  1. Open (project A) solution in Visual Studio.

  2. Right click on solution -> Add Existing Project -> then select the .csproj file of your external library (project B).

  3. Again in visual studio right click on (project A) -> Add -> Project Refference... -> and then add checkmark on your external library which you want to debug (project B).

  4. Finally place brake-points in (project A) where your external library (project B) is called and run with F5.

Solution 7 - Visual Studio

I was having a similar issue as my breakpoints in project(B) were not being hit. My solution was to rebuild project(B) then debug project(A) as the dlls needed to be updated.

Visual studio should allow you to debug into an external library.

Solution 8 - Visual Studio

NuGet references

Assume the -Project_A (produces project_a.dll) -Project_B (produces project_b.dll) and Project_B references to Project_A by NuGet packages then just copy project_a.dll , project_a.pdb to the folder Project_B/Packages. In effect that should be copied to the /bin.

Now debug Project_A. When code reaches the part where you need to call dll's method or events etc while debugging, press F11 to step into the dll's code.

Solution 9 - Visual Studio

The quickest way to do this on a one-off basis is to open the Proj B file directly in the Visual Studio instance in which you are editing and launching Project A (File => Open => File). You don't need to add the file to the solution. Just having it open in the editor will let you create your breakpoints directly in the Project B file.

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
QuestionKonstantinosView Question on Stackoverflow
Solution 1 - Visual StudioJaredParView Answer on Stackoverflow
Solution 2 - Visual StudioSarath KSView Answer on Stackoverflow
Solution 3 - Visual StudioTheGateKeeperView Answer on Stackoverflow
Solution 4 - Visual StudioMatrixManAtYrServiceView Answer on Stackoverflow
Solution 5 - Visual StudioTripleSView Answer on Stackoverflow
Solution 6 - Visual StudioLachezar LalovView Answer on Stackoverflow
Solution 7 - Visual StudioStefan MiticView Answer on Stackoverflow
Solution 8 - Visual StudiojasmintmpView Answer on Stackoverflow
Solution 9 - Visual StudiobbsimonbbView Answer on Stackoverflow