Debug .NET Framework Source Code in Visual Studio 2012?
Solution 1
Debugging .NET Framework sources was broken for a long time. See the relevant suggestion on VisualStudio UserVoice Allow developers to step through .NET Framework sources. Good news: it was finally been fixed! See the following blog post from Microsoft:
A new look for .NET Reference Source
In short:
- New web interface for browsing sources: http://referencesource-beta.microsoft.com/
- All sources, including project files, can be downloaded directly: http://referencesource-beta.microsoft.com/download.html (not compilable though)
- There's a new extension for F12 navigation: http://visualstudiogallery.msdn.microsoft.com/f89b27c5-7d7b-4059-adde-7ccc709fa86e
- Sources are always up to date and debugging isn't broken by patches and updates.
It's currently "beta". Eventually it's going to replace http://referencesource.microsoft.com/. Microsoft also promises to add sources of more assemblies.
Solution 2
This feature was broken in VS2010 SP1, it might be broken in VS2012 as well. Or Microsoft might release incorrect PDB files for the latest .NET Framework version (this had happened before). Try alternative solutions. I'm using .NET Reflector VSPro - it allows to decompile assemblies, load decompiled symbols during debugging and use full debugging features for these decompiled assemblies.
Solution 3
In VS 2008 I was able to debug .Net source, but in VS2012 I've got .NET Reflector (VS extension) installed, so it automatically decompiles and allows to debug any .Net code.
Another open source tool is ilspy.net , it saves the decompiled assembly as C# project and you can use the debugging tools.
There are also debugging tools for Windows, that come as part of SDK, but i haven't tried those: http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx
Solution 4
Here is a nice post describing how to configure VS symbol server and dotPeek 1.2 to debug decompiled code from VisualStudio: http://blog.jetbrains.com/dotnet/2014/04/09/introducing-dotpeek-1-2-early-access-program If debugging framework or other compiled code is your daily routine I would recommend to reconstruct solution from set of assemblies you use that will save time on symbols loading during debugger attach.
Solution 5
1) PDB files are not up to date. Try to uncheck Tool->Options->Debugging->General->"Require source files to exactly match the original version"
2) You've referenced another of your projects byadding it's dll to your references instead of adding the project as reference. Try to remove the reference add add a new reference to the project from the "Projects" tab
And you can search Google .It's giving more than answers
Related videos on Youtube
Imran Qadir Baksh - Baloch
Updated on June 06, 2022Comments
-
Imran Qadir Baksh - Baloch almost 2 years
I am using Visual Studio 2012. I want to Debug .NET Framework source code. I have tried nearly all the options but I am still getting
There is source code available for Current Location
. Symbols are loaded successfully. I have tried loading Microsoft Symbol Server and tried this url http://referencesource.microsoft.com/symbols. But I am still unable to DEBUG. I have tried these links, http://blogs.msdn.com/b/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx and http://msdn.microsoft.com/en-us/library/cc667410.aspxAlso followed this, http://blogs.msdn.com/b/dotnet/archive/2012/08/15/announcing-the-release-of-net-framework-4-5-rtm-product-and-source-code.aspx
Is anyone able to DEBUG .NET Framework source in VS 2012?
-
Shadow The Kid Wizard about 11 yearsAny change that you build the project in Release mode?
-
Eduard Dumitru about 11 yearsDownload a free trial of .NET Reflector. Install it and make sure it also installs the VS 2012 plugin (VS should be closed). Then follow the instructions in their documentation on how to make it so as that a referenced assembly which is not part of your solution is debuggable as if it were...
-
Imran Qadir Baksh - Baloch about 11 years@ShadowWizard, Nothing. The project is in DEBUG mode.
-
Shadow The Kid Wizard about 11 yearsSorry, meant "chance". Anyway, if you build simple "hello world" project, can you debug it? If not, something is wrong with the VS installation, try removing and make clean installation again.
-
Imran Qadir Baksh - Baloch about 11 years@ShadowWizard, Is it working with you in VS 2012?
-
Shadow The Kid Wizard about 11 yearsDon't have 2012 just yet (blush) but have enough experience with Debugging in older versions and don't think it changed that much.
-
Chen about 11 yearsDid you also checked "Enable .NET Framework source stepping"?
-
Imran Qadir Baksh - Baloch about 11 yearsYes I have also followed this, blogs.msdn.com/b/dotnet/archive/2012/08/15/…
-
Matt about 11 yearsMust be something wrong with your installation because I've been using 2012 for months and I can debug without issue. Wouldn't make sense to not be able to debug anyway.
-
Imran Qadir Baksh - Baloch about 11 years@Matt is you are debugging the .NET framework code or just your code
-
Chris Herring about 11 yearsI've got the same issue, followed the instructions didn't work, played around with all the settings still no luck
-
Csaba Toth about 11 years@Chris Herring, post owner: same issue here. Can I ask you what data you got and where after installing the reference source? The Readme.txt talks about selecting an arbitrary location, but there wasn't any question. I've found a ton of dlls and xmls in C:\Program Files (x86)\Reference Assemblies\, but no pdbs. So I'm not event sure if the reference source install was successful.
-
Csaba Toth about 11 years@ShadowWizard He doesn't have problem with debugging his own source code. But often you have a hundred story tall call stack and majority of it is system/.NET dll. With symbol debugging you can still see the signature of the functions on the call stack (of the "foreign" dlls), but you want to see at least the actual parameter values, and even better: the source code.
-
Csaba Toth about 11 years@Eduard Dumitru: Reflector is a great tool, and I'd advise it too (actually Visual Studio could do something like Reflector does if source code is not available, it seems that there's no advantage in being in MSIL land, I see x64 assembly). But Reflector it only allows only static analysis of the code. Often to see parameter and variable values on the call stack.
-
Csaba Toth about 11 yearsProgress: instead of off-line symbols I had partial success with the reference symbol server: link
-
Csaba Toth about 11 yearsBe sure to wipe out your symbol cache. If you have used the regular Microsoft symbol server, and downloaded pdbs, those are not as rich. They can prevent you from debugging.
-
Joel almost 11 yearstry to start visual studio with administrator permissions
-
user626528 almost 11 years@Csaba Toth, not really. Reflector VS plugin allows to decompile assemblies, load decompiled symbols during debugging and get full debugging features for these decompiled assemblies.
-
Csaba Toth almost 11 years@user626528 Thanks, good to know. I'll look into that.
-
BrainSlugs83 almost 11 yearsSame issue. I tried the official MSDN setup steps at msdn.microsoft.com/en-us/library/vstudio/… but it didn't change anything. Tried downloading manually installing the ~200 mb MSI file, and still nothing. Also quite hilarious that 0 of 9 people rated the official setup instructions as helpful. >.<
-
Csaba Toth almost 11 years@user626528 Oh, I was in the era of Reflector version 6. Reflector version 8 is brilliant. With the Pro version someone can debug into 3rd party dlls, set breakpoints, etc. Amazing.
-
-
Csaba Toth about 11 yearsWhat feature is broken exactly? The incorrectness of the pdbs shouldn't count that much after we uncheck "Require source files to exactly match the original version". In general, the symbol debugging feature and system pdb handling improved 2008->2010->2012. But this thing: debugging into the .NET source is different.
-
user626528 about 11 yearsFeature in the name of the question.
-
David Ebbo almost 11 yearsIndeed, the general agreement seems to be that the feature is broken.
-
Simon Mourier almost 11 yearsI don't think it's due to the version of Visual Studio, or the fact the feature doesn't work, it's just the only source (or PDB+source information) that was available was for .NET RTM version, and not all the service packs and updates that were released continuously after that holly point in time. @user626528 - do you have "alternative solutions"?
-
user626528 almost 11 years@Simon Mourier, well, I don't know exact reason. But for me it was working in VS2010 before SP1, and never after. Now I'm using .NET Reflector Pro instead - it allows debugging.
-
BrainSlugs83 almost 11 yearsReflector isn't as good of an option, as you can't see the comments, and sometimes logical structures get optimized away at compile time, etc, and Reflector can't recreate those. Also Reflector is expensive, and Microsoft supposedly gives us a better option (as I just described) for free.
-
BrainSlugs83 almost 11 yearsI didn't realize ILSpy could output an entire CSPROJ, NEAT!
-
user626528 almost 11 years@BrainSlugs83, what is optimized away - you can't debug, using any tools. Additional benefit of Reflector is that you can debug any assemblies, not only Microsoft's.
-
BrainSlugs83 almost 11 yearsHuh, on second though, the output project has lots of weird issues, missing the XML comments is a pretty huge one...
-
BrainSlugs83 almost 11 years@user626528 -- it used to work though. It would be better to fix the real issue. Using Reflector is a bad workaround. For example when loops are decompiled, sometimes they come out with random goto statements, or all kinds of bizarre code -- also the comments are missing, all you get is code. Reflector is fine if the code is closed source, but if it's open source (like the .NET framework), it's just stupid.
-
user626528 almost 11 years@BrainSlugs83, there is no much choice until MS fixes it.
-
BrainSlugs83 almost 11 yearsAssuming it's actually broken and not just some user introduced issue -- I mean, I see websites dedicated to debugging Microsoft's actual source, with VS2012 instructions (I can't make them work), but one would think that it's working somewhere, for someone.
-
user626528 almost 11 years@BrainSlugs83, nobody told he was able to make it working so far.
-
BrainSlugs83 almost 11 yearsThat's not correct. Look at the last answer provided by Grimace of Despair. He says it works for him, and links to a document that explains how to set it up for 2012 (a non MS document, with all kinds of weird steps) -- that being said, I followed those steps and it didn't work for me. Hence, I wonder if there is something wrong with my machine.
-
user626528 almost 11 years@BrainSlugs83, ughm, you can just try to make it working on a fresh VM installation. If you have any luck with this - let us now.
-
NH. almost 7 yearswas it rebroken again? their steps at referencesource.microsoft.com/setup.html don't work.