"Browse To Find Source" in Visual Studio 2010
Asked Answered
S

3

26

When is "Browse To Find source" enabled in Visual Studio 2010? (see below)

Enter image description here

In addition, I want to have it enabled so that I could browse to already-downloaded source code files from http://referencesource.microsoft.com/.

This would be useful since Microsoft doesn't always release PDB/source code at the same time with their latest patches. So if I want to step for example into DateTime, I really don't care about the latest patches which didn't involve DateTime. I just want to browse to its code which I downloaded from http://referencesource.microsoft.com/.

After some investigations I found dia2dump which is a useful tool to view PDB file contents. (It's in C:\Program Files (x86)\Microsoft Visual Studio 10.0\DIA SDK\Samples\DIA2Dump\)

It looks like when I can't see source code for something like DateTime, using .NET Framework stepping, a mscorlib.pdb file actually gets downloaded.

But if you look inside it with dia2dump it doesn't contain source file mappings. In other words useless, because even if you could browse to the source code like my initial idea, it wouldn't work because there are no source file mappings and no start addresses of the functions, and a lot of stuff missing :(

I think the solutions here are to use .NET Reflector Pro for or keep a virtual machine at hand, with releases of the framework which have source code and then disable updates.

Saturday answered 17/5, 2011 at 12:2 Comment(2)
The 'Cannot find or open the PDB file' message can appear in the module load output pane next to a loaded DLL even though you know the PDB file is present beside the DLL. In that case, simply do a clean on the DLL and recompile and often the DLL symbols will correctly load. In my estimation this is a VS bug since there is no way to force the PDB file's inclusion and using the clean option is non-intuitive.Citizenry
What lead me to doing the clean action was I noticed the timestamp never changed on the PDB file even though I recompiled and even though I deleted the PDB file before compiling. Only the clean action caused the PDB file to be regenerated.Citizenry
S
29

Introduction

Whenever you do a build from Visual Studio, normally, you also get a PDB file besides your executable file. You can see this file in the ..bin\Debug or ..bin\Release directory. This PDB file keeps a mapping to your source code lines and executable code in your assembly. Also, the original locations of the source code files from which a build was done is stored inside a PDB file. This means that if you build a class library which had a single file located at G:\ClassLibrary\Class1.cs, this path will be stored inside ClassLibrary.pdb. What is important to remember from all this is that without a PDB file it is impossible to do source code step-in debugging.

Real-life scenario

So, suppose I do a build on my drive G:\ClassLibrary1, for a class library.

I give you a ClassLibrary.dll and a ClassLibrary.pdb file, or you get them by checking them out from source control.

You reference the ClassLibrary.dll in your project and you use a class from the library.

If you now try to step into class code from the library the following will happen:

Visual Studio tries to locate a ClassLibrary.pdb file in a couple of locations

  • 1.1 If it doesn't find it, you get a "Browse to find source" disabled page. Remember, you can't debug without a valid PDB file.

  • 1.2 If it does find a PDB file, it looks inside the PDB file and sees that you are trying to debug Class1.cs which was originally built from

    G:\ClassLibrary1\Class1.cs
    

    and looks on your computer for that file.

  • 1.2.1 If it finds it, it steps into the code automatically.

  • 1.2.2 If it doesn't find it, you get the following dialog:

Browse to source file

If you press Cancel, you will be presented with the: "No source available" and you will have "Browse to find source" enabled in this case.

Enter image description here

Why? Because you have a valid PDB file, but Visual Studio can't possibly know where you have the source code for ClassLibrary1 on your computer or if you even have it on your computer. That's why you got the dialog -> so that you can point Visual Studio to the exact location of the source code file.

Final notes

So what will you do when you get a browse to find source disabled?

In Visual Studio, you open menu Debug -> Windows -> Call stack.

You right click on the top call stak instruction and you choose "Symbol Load Information". It will show you the locations where Visual Studio has tried to find a valid PDB file.

  • 1.a If you only see "Cannot find or open PDB file" messages put a valid PDB file at any of these locations. (You might have to scroll right to see the messages) Stop and start debugging again.
  • 1.b If you see a "PDB does not match the image" message it means the following. Visual Studio has found a PDB file, but it is for another build. If I build ClassLibrary1.dll and give it to you, and then I build it again without changing a single line of code and then give you the PDB, and you try to debug classLibrary1.dll you will get this message. The assembly and its PDB file must be exactly from the same build, otherwise you will get this message. (This check is done using some unique number put inside the assembly and PDB file every time you do a built)
  • 1.c You see a "symbols loaded" message but still get a "Browse to find" disabled. It means that the PDB file you have is not good for step-in debugging. Some PDB files you try to use don't have all the information in them necessary for step-in debugging. I think you can control this from somewhere in the advanced build settings, but I haven't tried it though, because I want to have usable PDB files generated everytime I do a build. This situation often happens if you try to debug the source code of the .NET framework itself and Microsoft hasn't put usable PDB files for the source code, but instead Microsoft has put some PDB files which can't be used for step-in debug. This happens more often than you think, because often Microsoft makes updates (patches) to the .NET Framework source code. These updates silently install onto your computer via Windows Update, and you are surprised to see that yesterday you could debug .NET Framework source code and today you can't. It usually takes some time until they put a valid PDB file for the latest code. In this case you can use .NET Reflector Pro step-debug ability or a virtual machine which has a .NET framework version with usable PDB files and disable Windows Update on that machine.
Saturday answered 18/5, 2011 at 16:28 Comment(4)
So what instructions are to enable the dialog/link?Basanite
@Basanite you can't enable it. The first step you do if you get “No source code available” is right click on the top call-stack instruction, choose “Symbol Load Information” and be sure you have a “Symbols loaded” message somewhere there. If you don’t see any “Symbols loaded”, then you should try placing the pdb at one of the locations which is listed there. Also the pdb has to have source line numbers information inside it.Saturday
My problem is that I've loaded the symbols (of System.Web from MS Symbols Server - I see that in Modules windows), but the menu/dialog is still disabledBasanite
If that's the case, then the pdb Microsoft Symbol Server is giving you doesn't contain source line number informations, hence it is unusable for debug stepping purposes. You can double check this by using dia2dump to look inside the pdb MS is giving you. Unfortunateley, this happens quite often because of patches. The options I know of are: reflector pro, VM with a .net framework version where there is a good System.Web pdb from MS or download the .net sources from referencesource.microsoft.com/netframework.aspx and look inside them (without debugging).Saturday
A
0

Check out the article Step Into .NET Framework 4.0 Source Code.

If you encounter the “No Source Available” screen, try to press “Browse to Find Source” and find the file you need in the source directory. You should probably need to use files search to find it. This is done only once, since from now on Visual Studio remembers this location and searches there for missing source files.

I hope it's about what you are looking for.

Axis answered 17/5, 2011 at 13:32 Comment(2)
the guy who wrote the article didn't actually do what he states in the article. As you can see, "Browse to source" is also disabled in the screenshot he provided in the article.Saturday
I think there is something wrong with your settings. Try to double check them. Have you tried to follow steps described in troubleshooting(referencesource.microsoft.com/troubleshooting.aspx) section?Axis
T
0

Similar issue in Visual Studio 2019 can be resolved by checking "Enable Just My Code".

Debug > Options... > Debugging > General > Enable Just My Code

enter image description here

More detail explanation can be found here How to fix debugger is looking for executioncontext.cs

Tillford answered 20/8, 2020 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.