简体   繁体   中英

stepping into .Net 4.0 framework source

I have .Net framework v4.0.30319 SP1Rel and visual studio 2010 v 10.0.40219.1 SP1Rel (data taken from about dialog in VS).

.Net 4.0 is available here http://referencesource.microsoft.com/netframework.aspx but not sure which specific version that is, and whether it is compatible with my setup. I did download the source a month or two back but I couldn't step into the framework source (no source available message). I read around at the time and it seemed to be due to updates for VS (and presumably the installed framework binaries) superseding the source version.

Before I try downloading again, could someone please confirm whether the source is now in line with and compatible with the latest versions. If not, is there an alternative (perhaps 3rd party) tool that allows stepping into the source?

EDIT: OK, just saw this http://social.msdn.microsoft.com/Forums/en-US/refsourceserver/thread/41388c7b-582b-4e3f-8178-3d38a3c99639 and this does indicate you cannot use the current source code?

To answer the second part, the professional version of .NET Reflector allows you to step into assemblies for which you do not have the source (including the .NET framework) while you debug your code. It will automatically decompile the assemblies and give you line-by-line debugging support on the decompiled code.

The latest version of Resharper may also offer a similar feature.

Of course, you won't get the nice variable names and comments that you get when using the reference source.

Once you've made all the appropriate settings, you can use the following workaround. The workaround is essentially to find the security updates that caused the dll to change, and then remove them. This has the obvious downside of having those security updates removed on your machine.

Workaround

  1. Identify which dll you want to debug into (eg System.Windows.Forms.dll)
  2. While debugging, open the Modules window in Visual studio, find the Version column. If the version is not the RTM or Service pack version, then you'll need to do the workflow. Typically the RTM dll will say "built by: RTMRel". While a dll that was part of a security update will say "built by: RTMGDR". Note the version number (for example 4.0.30319.269 built by: RTMGDR)
  3. Now, we want to find the update that created this version. Do this by searching for the dll and version number at support.microsoft.com/kb/ For example, I did the following google search: site:support.microsoft.com/kb System.Windows.Forms.dll 4.0.30319.269
  4. The search should turn up information about an update. Note the KB number in the address bar. In my example the address was http://support.microsoft.com/kb/2604121 , so KB2604121, is what we're interested in.
  5. Go to Control Panel->Programs and Features, and click "View Installed Updates"
  6. Find an update which lists the KB number (you can use the search in the upper right box).
  7. Uninstall that update.
  8. Repeat this process for this same dll until the dll is back to its RTMRel version or SP version. For example, for System.Windows.Forms.dll, I had to remove KB2686827, KB2604121, KB2518870 before it was back to the RTMRel version.

You'll need to do this for each dll within the .NET framework that you care about debugging into.

Once that's done, set a breakpoint within the .net source (for example, go to the Breakpoints tab, say New->Break at Function, and enter System.Windows.Forms.Form.Form) or step into one of the .net methods in that dll.

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:

It's currently "beta". Eventually it's going to replace http://referencesource.microsoft.com/ . Microsoft also promises to add sources of more assemblies.

To debug .Net source, just tick the option in Visual Studio (while debugging).

Here are the full instructions: How to: Debug .NET Framework Source

Be aware you may have to untick "Just My Code" in order for some behavior you might expect to work (such as dropping breakpoints in the .Net source).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM