32

I am using Visual Studio 2013 and have a .NET 4.5.2 project. I have setup my settings according to following page:

http://referencesource.microsoft.com/setup.html

With this setup, I can see that all necessary symbols are downloaded and loaded but I cannot step into a code like the following:

var cookieContainer = new System.Net.CookieContainer();

I am getting a Source Not Available message.

I can step into the following code just fine:

Console.WriteLine("test");

Do you have any idea why I can step into code from mscorlib.dll but cannot step into code from System.dll?

huseyint
  • 14,953
  • 15
  • 56
  • 78
  • 1
    Cleaning the symbol cache helped me when I was facing the same issue last time. Even though VS displayed that the symbols are loaded for .net modules, the step into function doesn't worked. Try to clean the cache and let the VS reload the new symbols: Tools->Options->Debugging->Symbols->Empty Symbol Cache – Zoltan Tirinda Mar 24 '16 at 12:11

2 Answers2

26

and have a .NET 4.5.2 project

The version number is your problem. It is a general problem with the Reference Source, Microsoft does not keep it updated well enough to supply source for new framework versions. And more troubling, for security and stability updates. The guys that worked on this are well aware of this problem, they noted this as an issue in their presentation but it has currently, and always had, the status of a // todo item.

It is something you can visualize, first delete System.pdb from your symbol cache (the one in MicrosoftPublicSymbols). Then start debugging your test program, the debugger will retrieve a new PDB from the server. Use Debug > Windows > Modules, right-click System.dll and select "Symbol Load Information". On my machine that looks like:

C:\projects2\ConsoleApplication407\bin\Debug\System.pdb: Cannot find or open the PDB file.
C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.pdb: Cannot find or open the PDB file.
C:\Windows\System.pdb: Cannot find or open the PDB file.
C:\Windows\symbols\dll\System.pdb: Cannot find or open the PDB file.
C:\Windows\dll\System.pdb: Cannot find or open the PDB file.
C:\temp\symbols\System.pdb\c464b02c2bf04080adcad166dc729c151\System.pdb: Cannot find or open the PDB file.
C:\temp\symbols\MicrosoftPublicSymbols\System.pdb\c464b02c2bf04080adcad166dc729c151\System.pdb: Cannot find or open the PDB file.
SYMSRV:  C:\temp\symbols\System.pdb\C464B02C2BF04080ADCAD166DC729C151\System.pdb not found
SYMSRV:  http://referencesource.microsoft.com/symbols/System.pdb/C464B02C2BF04080ADCAD166DC729C151/System.pdb not found
http://referencesource.microsoft.com/symbols: Symbols not found on symbol server.
SYMSRV:  System.pdb from http://msdl.microsoft.com/download/symbols: 96985 bytes 
http://msdl.microsoft.com/download/symbols: Symbols downloaded from symbol server.
C:\temp\symbols\System.pdb\C464B02C2BF04080ADCAD166DC729C151\System.pdb: Symbols loaded.

You can see it searching for the PDB in the normal locations and not finding it. Then contacting the SYMSRV. It first goes to http://referencesource.microsoft.com, as it should, but that server says "not found". And you'll get the copy from the regular msdl server, the stripped one that doesn't have the necessary file + line number debugging info.

There is no clean fix for this, you'd have to downgrade your machine again to the reference source version. Something I cannot do, using Windows 8.1. And should not do, I use VS2013. Redgate's Reflector is an alternative.

I created a UserVoice item for this, it needs a lot more votes.


Update: the Reference Source is now updated to 4.5.2 (March 2015)

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 2
    Thanks bunch. This also helped: http://stackoverflow.com/q/8139269/39 "The PDBs for stepping through the source code are only posted for RTM and Service Packs. As such, when security update comes out and it modifies the dll you are trying to debug, it will cause source stepping to not work (that is, you'll get the "No source Available" with a greyed out "Browse to find Source")." – huseyint Dec 26 '14 at 10:08
  • I am also getting the same behavior even if I downgrade to 4.5.1 btw. – huseyint Dec 26 '14 at 10:09
  • You probably missed the "more troubling, for security and stability updates" part of the answer. – Hans Passant Dec 26 '14 at 10:20
  • Ah ok, yes, missed that part :) – huseyint Dec 26 '14 at 12:51
  • Is Reference Source at 4.6.2 yet? https://referencesource.microsoft.com/ implies it is, but I can't step into source. I tried to confirm with the technique above, but there are no "SYMSRV:" entries (VS2015 Update 3). – Jon Jan 27 '17 at 03:04
  • What if the .net version at Rererence Source (4.8) is newer than the .net version that I'm using (4.6)? I've downloaded the 4.6 source code, but when stepping into it, I see the wrong lines (e.g. the curser executes comments and blank lines). – Tobias Knauss May 24 '19 at 12:04
  • The framework code is optimized release quality, stepping in general is not going to act predictably. You do need to lower the odds for a mismatch by installing 4.8 on your machine as well. What version you target in your project does not matter. – Hans Passant May 24 '19 at 12:15
  • "[..] you'd have to downgrade your machine again to the reference source version". Yea I've been trying to do that all morning now, but unfortunately I cannot find the exact version they used on referencesource anywhere... Without that, it's practically impossible to get the version right. Am I overlooking something? – atlaste Apr 20 '20 at 09:29
20

JetBrains DotPeek (currently version 1.2) has a very nice feature which lets you not only generate pdbs but also to serve those pdbs locally through a built in Symbol Server to provide symbols to Visual Studio when you're debugging. Obviously the source code is decompiled code rather than the actual source but it can be very helpful none the less for those times when the normal MS symbol servers aren't giving you the pdbs you need.

Information about the symbol server feature can be found on their website.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
kjbartel
  • 10,381
  • 7
  • 45
  • 66
  • 9
    It's so ridiculous that Microsoft can't straighten out their symbol servers and needed references so that debugging into .NET framework classes is a "just works" feature. Visual Studio should be able to resolve any framework references to source without any tweaks... I too purchased DotPeek and am using it to debug .NET framework classes. (Thank you JetBrains for making such a product!) – Jazimov Jul 08 '18 at 20:25
  • Using any decompilation tool means you don't have interesting information, such as comments and some names. This might be sufficient for some purposes, but I'd rather have the reference source to be honest. – atlaste Apr 20 '20 at 09:30
  • THIS WORKS^^ more instructions here https://hmemcpy.com/2014/07/how-to-debug-anything-with-visual-studio-and-jetbrains-dotpeek-v1-2/ – diox8tony Sep 15 '22 at 21:55