174

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?

kaya3
  • 47,440
  • 4
  • 68
  • 97
Kostas Konstantinidis
  • 13,347
  • 10
  • 48
  • 61

9 Answers9

246

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
Midas
  • 7,012
  • 5
  • 34
  • 52
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • 8
    the specific checkbox was unchecked already. What i noticed though, is that it does enter into a method of the external library, but it steps over when i try to call a method that is part of an interface. – Kostas Konstantinidis Mar 17 '09 at 15:41
  • You might need to go to the properties of a DLL, and ensure that Copy Local is set to True. Otherwise, Modules won't be able to find the .pdb for your reference. – Bryan Rayner Nov 25 '14 at 18:21
  • 1
    *Just My Code* doesn't seem to make any difference (I can jump into external code even with it enabled), but finding the module in the debugger helps. – TheOperator Dec 30 '15 at 22:43
  • 12
    A matching symbol file was not found in this folder. – Christine Feb 23 '17 at 19:53
  • 3
    If you don't have PDB files for a referenced module, ReSharper can be used to decompile binaries using the "Load Symbols with ReSharper Deecompiler" option in the right-click menu in Debug/Windows/Modules. very powerful. – emilast Jan 12 '18 at 08:15
  • 2
    @Christine If you encounter "A matching symbol file was not found in this folder." then look up the reference in the project, delete it, build the sources of the reference locally and reference the output dll. With that dll, if build locally, comes a PDB file, that is picked up automatically now. So just for debugging purposes you change the reference temporarily, – Mike de Klerk Jul 12 '19 at 11:50
  • 1
    Any other option apart from Installing ReSharper for "Load Symbols with ReSharper Deecompiler" or building by yourself ? – Black_Rider Apr 05 '21 at 12:13
  • @MikedeKlerk's answer worked for me - was using a personal NuGet build before. – stigzler Dec 28 '21 at 17:30
  • Didn't get this to work even with symbols loaded for the external library. – AH. Jun 19 '23 at 12:10
21

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

Sarath Subramanian
  • 20,027
  • 11
  • 82
  • 86
15

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.

TheGateKeeper
  • 4,420
  • 19
  • 66
  • 101
6

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.

MatrixManAtYrService
  • 8,023
  • 1
  • 50
  • 61
3

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.

Lachezar Lalov
  • 477
  • 6
  • 6
1

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.

jasmin
  • 171
  • 1
  • 5
1

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.

bbsimonbb
  • 27,056
  • 15
  • 80
  • 110
1

[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.

TripleS
  • 1,216
  • 1
  • 23
  • 39
0

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.

Stefan Mitic
  • 1,551
  • 1
  • 8
  • 8