23

When debugging the opened solution/project in Visual Studio (2015) I would like to debug (step into) a method call which is located in one of the referenced assemblies. The assembly has .pdb (copied local) and source code. This assembly actually is also my class lib project, but not in the current solution, instead in an other solution.

I know the trivial solution to debug this assembly would be adding its project to the current solution instead of referencing it, then debugging experience would be seamless. However for some reasons this would not be too efficient in my case, for example there are many assemblies (dozens) which I should add and I do not want to end with a giant solution.

What I've done/tried so far:

  • I've unchecked Just my code
  • I've checked that .pdb for the other assembly is copied to my current project's output folder.
  • Tried to set a breakpoint just before the call, then step into. No success, the call was just stepped over.
  • The assembly I would like to debug is coming as a NuGet package (not a simple browsed reference). Still true, it's my class lib project, comes with .pdb, and the source code is available in my local disk.
  • Looked at Window->Debug->Modules: Symbol status: Symbols loaded. User Code: N/A. Symbol File location is a Temp Asp Files. (It is an ASP.NET MVC application)
  • Because it is coming from a NuGet package its build is a Release build, but currently not optimized, and has the up to date .pdb

As I recall this debugging feature was sometimes surprisingly worked automagically, however now it does not.

What am I missing?

8
  • Look at Window->Debug->Modules - it'll tell you if PDB matches (most likely problem). Commented Aug 19, 2015 at 5:09
  • For that particular assembly: Source Code: N/A and Symbol Status: Symbols loaded, symbol file located in Temp Asp Files Commented Aug 19, 2015 at 5:17
  • Can you attach the debugger from the class library solution to your main executable instead? Commented Aug 19, 2015 at 5:27
  • @BrendanGreen Main executable is IIS as it is an ASP.NET project. Also I would like to debug the source in the current solution also. I remember this feature I am asking for worked for me once... Commented Aug 19, 2015 at 5:29
  • Maybe sources don't match exactly... There should be checkbox to allow version mismatch for source... Commented Aug 19, 2015 at 7:27

3 Answers 3

21

Most common reasons of such experience are:

  1. enabled "my code only" (tools->options->debugging)
  2. mismatched PDBs
  3. mismatched sources

You've ruled out 1, so to check the other 2:

Open Debug->Windows->Modules and find assembly you are having problem with. Make sure it is loaded from location you expect, has version you expect, check if PDBs are loaded. You may need to try load/reload PDB to see if VS is happy with PDB it located.

If PDBs are matching VS should start asking about source location. Information about source is part of PDB so it will let you know if source matches or not (there is option to allow loading mismatched source files, but you'll get funny debugging expirience).

Note that if you library build for RELEASE it will be optimized and for some function you'll not be able to debug them at all due to inlining at JIT time or compile time optimizations of dead code (like if (false) branches). For best expirience make sure to use DEBUG assembly with matching PDB and make sure to attach early with "suppress optimizations on load" in debugger options.

1
  • 1
    Thx your suggestions about looking at Window->Debug->Modules. I found the problem: In the module window I've tried explicitly load the .pdb and got "PDB does not match image" error. It turned out, the .pdb produced by release build was not suitable for debugging (btw then is it suitable for what?), because of 2 reasons: a) The compile was optimized, b) The .pdb option in Project properties/Build/[Advanced] was set to "PDB only" instead of "Full". To wrap it up: It is an ugly feature of VS, that even an up to date matching .pdb and source is located Commented Aug 20, 2015 at 7:29
1

I have faced this problem as well and I have tried many tips. Yet I found out the problem in my context was:

  • The desired .dll was installed into GAC (Global Assembly Cache).

I removed it and I could step into the dll code again.

0

I need to do this many times and simple approach I followed is :

1) Ensure class library you want to debug is build with latest source code

2) Copy dll and .pdb files from bin/debug directory of class library into application output directory

3) Run the application withattaching debugger(if it is web application, directly access it from browser and if it is console/winform/wpf - just click respective exe)

4) Attach visual studio open with class library source code with that particular process exe ( or WP3 IIS worker process for web application) and all set to go !!

1
  • How do you do item 4?
    – niico
    Commented Aug 10, 2018 at 22:00

Your Answer

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

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