如何启用“启用 .NET Framework 源步进”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8139269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:02:03  来源:igfitidea点击:

How do you enable "Enable .NET Framework source stepping"?

.netvisual-studio-2010visual-studio

提问by Ian Boyd

Update 22nd Feb 2013: The Microsoft Connect entry has note from Alok Shriram (Program Manager, Base Class Libraries, .NET Framework) that the issue should now be resolved. The Connect entry is marked as Resolved (Fixed):

2013 年 2 月 22 日更新:Microsoft Connect 条目有来自 Alok Shriram(程序管理器、基类库、.NET 框架)的说明,该问题现在应该得到解决。Connect 条目被标记为Resolved (Fixed)

This issue should now be fixed. We published an update to reference sources. Please let us know in case your issue is still not fixed.

现在应该修复这个问题。我们发布了对参考来源的更新。如果您的问题仍未解决,请告诉我们。

Year and a half.

一年半。

Bonus Links

奖金链接

Original Question

原始问题

How do I enable .NET framework source stepping in Visual Studio 2010?

如何在 Visual Studio 2010 中启用 .NET 框架源步进?



Note: This question is one piece of a larger whole:

注意:这个问题是一个更大的整体:



Visual Studio 2010 comes with a new feature:

Visual Studio 2010 带有一个新功能:

  • Tools, Options, Debugging, General, Enable .NET Framework source stepping
  • 工具、选项、调试、常规、启用 .NET Framework 源步进

Screenshot of options menu

选项菜单的屏幕截图

Following the instructions on the MSDN page How to: Debug .NET Framework Source:

按照 MSDN 页面How to: Debug .NET Framework Source 上的说明进行操作

To enable .NET Framework source debugging

  1. On the Toolsmenu, click Options.

  2. In the Optionsdialog box, click the Debuggingcategory.

  3. In the Generalbox, select the following check boxes:

    • Enable .NET Framework source stepping
    • Enable source server support

启用 .NET Framework 源代码调试

  1. 工具菜单上,单击选项

  2. 选项对话框中,单击调试类别。

  3. 常规框中,选中以下复选框:

    • 启用 .NET Framework 源步进
    • 启用源服务器支持

I do this:

我这样做:

Screenshot of options menu, highlighting the relevant options selected

选项菜单的屏幕截图,突出显示所选的相关选项

Note: You will note, as the MSDN page notes, and as I noticed, that checking Enable .NET Framework source steppingwill automatically uncheck **Enable Just My Code (Managed only). I also enabled the diagnostic messages of source server support.

注意:您会注意到,正如 MSDN 页面所指出的,并且正如我所注意到的,选中启用 .NET Framework 源代码步进将自动取消选中 **Enable Just My Code (Managed only)。我还启用了源服务器支持的诊断消息。

Enabling those options automatically set a symbol cache download location for me:

启用这些选项会自动为我设置符号缓存下载位置:

Screenshot of options menu, showing cache directory (highlighted)

选项菜单的屏幕截图,显示缓存目录(突出显示)

Note: The Microsoft Symbol Serverentry is already present (and cannot be removed).

注意Microsoft Symbol Server条目已经存在(并且无法删除)。



The MSDN page says to load the symbols:

MSDN 页面说要加载符号:

To load Framework symbols using the Modules window

  1. In the Moduleswindow, right-click a module for which symbols are not loaded. You can tell if symbols are loaded or not by looking at the Symbols Statuscolumn.

  2. Point to Load Symbols Fromand click Microsoft Symbol Serversto download symbols from the Microsoft public symbols server or Symbol Path to load from a directory where you have previously stored symbols.

使用模块窗口加载框架符号

  1. 在“模块”窗口中,右键单击未加载符号的模块。您可以通过查看符号状态列来判断符号是否已加载。

  2. 指向加载符号自并单击Microsoft 符号服务器以从 Microsoft 公共符号服务器或符号路径下载符号以从您之前存储符号的目录加载。

I try this:

我试试这个:

enter image description here

在此处输入图片说明

and then all the symbols are loaded:

然后加载所有符号:

Screenshot of modules window, as described above

模块窗口的屏幕截图,如上所述

I’ve been sitting on a breakpoint, which is about to call into .NET framework code:

我一直坐在断点上,即将调用 .NET 框架代码:

Screenshot of code, transcribed below

Screenshot of code, transcribed below

protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
{
    base.ScaleControl(factor, specified);

Pushing F11causes the debugger to simply skip to the next line:

推送F11会导致调试器简单地跳到下一行:

Screenshot of code, transcribed below

Screenshot of code, transcribed below

protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
{
    base.ScaleControl(factor, specified);

    //Record the running scale factor used
    this.scaleFactor = new SizeF(
            this.scaleFactor.Width * factor.Width,
            this.scaleFactor.Height * factor.Height);

How do I enable .NET Framework source stepping in Visual Studio 2010?

如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?



I am sitting at a breakpoint in my code. I try double-clicking on a function further up in the call stack. This would, I hope, allow me to jumpto the .NET code:

我正坐在我的代码中的断点处。我尝试双击调用堆栈中更上层的函数。我希望这能让我跳到.NET 代码:

enter image description here

enter image description here

Except that it doesn't work: Visual Studio tells me that there's no source available:

除了它不起作用:Visual Studio 告诉我没有可用的源:

Screenshot of error message saying No Source Available

Screenshot of error message saying No Source Available

How do I enable .NET Framework source stepping in Visual Studio 2010?

如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?



If I switch to disassembly view before trying to step into .NET code (Debug-> Windows-> Disassembly), I can see a callinto the .NET code:

如果我在尝试进入 .NET 代码(调试-> Windows->反汇编)之前切换到反汇编视图,我可以看到call.NET 代码:

Screenshot of code

Screenshot of code

And when I do, I end up debugging a disassembly of System.Windows.Forms.ScaleControl:

当我这样做时,我最终调试了以下反汇编System.Windows.Forms.ScaleControl

Screenshot of disassembly window

Screenshot of disassembly window

Which isn't the same as, or as useful as, being able to step into the .NET Framework source.

这与能够单步进入 .NET Framework 源代码不同,也不同。

How do I enable .NET Framework source stepping in Visual Studio 2010?

如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?



The configured symbol cache path on my computer does contain symbol cache files:

我电脑上配置的符号缓存路径确实包含符号缓存文件:

Screenshot of folder listing

Screenshot of folder listing

So it is downloading pdbsymbol files, but refusing to use them.

所以它正在下载pdb符号文件,但拒绝使用它们。

How do I enable .NET Framework source stepping in Visual Studio 2010?

如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?



Leppie suggested that I check the Debuglog (with the debug log window open; otherwise it doesn't log anything):

Leppie 建议我检查Debug日志(打开调试日志窗口;否则它不会记录任何内容):

Step into: Stepping over method without symbols 'System.Windows.Forms.Form.ScaleControl'

Earlier in the log I see it loading symbols for System.Windows.Forms.dll:

在日志的早些时候,我看到它加载了以下符号System.Windows.Forms.dll

Loaded 'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Symbols loaded.

enter image description here

enter image description here

So it isfinding my symbols, but claiming that it couldn't find them.

所以它正在寻找我的符号,但声称它找不到它们。

How do I enable .NET Framework source stepping in Visual Studio 2010?

如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?



A guy from Microsoft Italy suggests turning off Require source files to exactly match original version:

来自意大利微软的一个人建议关闭需要源文件以完全匹配原始版本

Screenshot of options window

Screenshot of options window

That didn't fix it.

那没有解决它。

How do I enable .NET Framework source stepping in Visual Studio 2010?

如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?



It has been suggested that there's a bug with Microsoft's source server for .NET Framework 4.0. Following that suggestion, I switched the project to target .NET Framework 3.5:

有人建议 Microsoft 的.NET Framework 4.0源服务器存在错误。根据该建议,我将项目切换到目标.NET Framework 3.5

enter image description here

enter image description here

That didn't fix it.

那没有解决它。

How do I enable .NET Framework source stepping in Visual Studio 2010?

如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?



Someone somewhere idly wondered whether another person experiencing the same problem was using the 64-bit version of the debugger. Now, there's no such thing as a 64-bit version of Visual Studio, but I tried switching my project from AnyCPUto x86(it was being JITed to x64), in case Microsoft doesn't support 64-bit processors:

某个地方的某个人漫不经心地想知道​​是否另一个遇到同样问题的人正在使用 64 位版本的调试器。现在,没有 64 位版本的 Visual Studio,但我尝试将我的项目从AnyCPU切换到x86(它被JITed到 x64),以防 Microsoft 不支持 64 位处理器:

enter image description here

enter image description here

That didn't fix it:

那没有解决它:

Step into: Stepping over method without symbols 'System.Windows.Forms.Form.ScaleControl'

How do I enable .NET Framework source stepping in Visual Studio 2010?

如何在 Visual Studio 2010 中启用 .NET Framework 源代码步进?



See also

也可以看看

采纳答案by Matt Smith

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").

用于单步执行源代码的 PDB 仅针对 RTM 和 Service Pack 发布。因此,当安全更新发布并修改您尝试调试的 dll 时,它将导致源单步执行不起作用(也就是说,您将获得带有灰色“浏览以查找源”的“无源可用” ”)。

However, 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.

但是,完成所有适当的设置后,您可以使用以下解决方法。解决方法本质上是找到导致 dll 更改的安全更新,然后将其删除。这具有在您的计算机上删除这些安全更新的明显缺点。

Workaround

解决方法

  1. Identify which dll you want to debug into (e.g. System.Windows.Forms.dll)
  2. While debugging, open the Moduleswindow in Visual studio, find the Versioncolumn. 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.
  1. 确定要调试的 dll(例如 System.Windows.Forms.dll)
  2. 调试时,在 Visual Studio 中打开Modules窗口,找到Version列。如果版本不是 RTM 或 Service Pack 版本,则您需要执行工作流。通常,RTM dll 会显示“构建者:RTMRel”。虽然作为安全更新一部分的 dll 会显示“构建者:RTMGDR”。请注意版本号(例如 4.0.30319.269 构建者:RTMGDR)
  3. 现在,我们要找到创建此版本的更新。为此,请在 support.microsoft.com/kb/ 上搜索 dll 和版本号。例如,我进行了以下 google 搜索: site:support.microsoft.com/kb System.Windows.Forms.dll 4.0.30319.269
  4. 搜索应显示有关更新的信息。请注意地址栏中的 KB 编号。在我的示例中,地址是 http://support.microsoft.com/kb/2604121,因此 KB2604121 是我们感兴趣的。
  5. 转到控制面板-> 程序和功能,然后单击“查看已安装的更新”
  6. 查找列出 KB 编号的更新(您可以使用右上角框中的搜索)。
  7. 卸载该更新。
  8. 对同一个 dll 重复此过程,直到 dll 恢复到其 RTMRel 版本或 SP 版本。例如,对于System.Windows.Forms.dll,在回到RTMRel版本之前,我必须删除KB2686827、KB2604121、KB2518870。

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

您需要对 .NET 框架中您关心调试的每个 dll 执行此操作。

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.

完成后,在 .net 源文件中设置一个断点(例如,转到 Breakpoints 选项卡,说 New->Break at Function,然后输入 System.Windows.Forms.Form.Form)或步入其中一个 .net该dll中的方法。

回答by yoel halb

While unfortunately there is a problem with a Microsoft, as Leppie pointed out (and I got the same result see

不幸的是,正如 Leppie 指出的那样,Microsoft 存在问题(我得到了相同的结果,请参阅

it should be noted that your attempt would fail anyway, since you referenced:

应该注意的是,您的尝试无论如何都会失败,因为您引用了:

  • Microsoft Symbol Server
  • 微软符号服务器

instead of:

代替:

  • referencesource.microsoft.com/symbols
  • referencesource.microsoft.com/symbols

See the FAQ/Troubleshooting section of Configuring Visual Studio to Debug .NET Framework Source Code

请参阅配置 Visual Studio 以调试 .NET Framework 源代码的常见问题/疑难解答部分

回答by leppie

I have found the answer, I think.

我已经找到了答案,我想。

I traced what was happening on Fiddler. It seems only the symbols are currently available, and no source.

我追踪了 Fiddler 上发生的事情。目前似乎只有符号可用,没有来源。

When VS tries to load the symbols from the 'referencesource' server it fails (404). As this fails, I think it cannot map to source files on that server.

当 VS 尝试从“参考源”服务器加载符号时,它会失败(404)。由于这失败了,我认为它无法映射到该服务器上的源文件。

http://referencesource.microsoft.com/symbols/mscorlib.pdb/ED96A7F38A2940F39B9CA7AD9BC5CB671/mscorlib.pdb

http://referencesource.microsoft.com/symbols/mscorlib.pdb/ED96A7F38A2940F39B9CA7AD9BC5CB671/mscorlib.pdb

After the above failure, it tries some server called 'msdl' where it finds the actual PDB (but it appears this one have no source code info).

在上述失败后,它会尝试一些名为“msdl”的服务器,在其中找到实际的 PDB(但似乎该服务器没有源代码信息)。

http://msdl.microsoft.com/download/symbols/mscorlib.pdb/ED96A7F38A2940F39B9CA7AD9BC5CB671/mscorlib.pd_

http://msdl.microsoft.com/download/symbols/mscorlib.pdb/ED96A7F38A2940F39B9CA7AD9BC5CB671/mscorlib.pd_

All in all, it appears to be a (temporary) Microsoft issue with their servers.

总而言之,这似乎是微软服务器的(临时)问题。

I am sure I had some source code a while back. But now it is not working.

我确信我有一些源代码。但现在它不工作了。

Edit:

编辑:

I tried it with various .NET versions, all the same result. :(

我尝试了各种 .NET 版本,结果都一样。:(

回答by watbywbarif

For now it is not working if you have SP1 installed. Here are some comment about problem form MS: http://social.msdn.microsoft.com/Forums/en-US/refsourceserver/thread/41388c7b-582b-4e3f-8178-3d38a3c99639

如果您安装了 SP1,现在它不起作用。以下是关于 MS 问题的一些评论:http: //social.msdn.microsoft.com/Forums/en-US/refsourceserver/thread/41388c7b-582b-4e3f-8178-3d38a3c99639

回答by Brian Chavez

In my case, I was debugging an old .NET 2.0WinFormsapplication and I got the "Source Not Available"message. I tried all the recommended settings.

就我而言,我正在调试一个旧的.NET 2.0 WinForms应用程序,并收到“源不可用”消息。我尝试了所有推荐的设置。

Ultimately, I rebuilt the app to temporarily target .NET 4.5and was able to get the source stepping to work. Perhaps my app was just too old for source stepping. Kind of defeats the purpose, I know, but for quick and dirty testing it works. The bug I have is still present in .NET 4.5. :)

最终,我重新构建了应用程序以临时面向.NET 4.5,并且能够使源代码步进工作。也许我的应用程序对于源代码步进来说太旧了。我知道这有点违背目的,但对于快速和肮脏的测试,它是有效的。我的错误仍然存​​在于.NET 4.5 中。:)

Target Framework

Target Framework

回答by Colonel Panic

Here are the official instructions https://referencesource.microsoft.com/setup.html

这里是官方说明https://referencesource.microsoft.com/setup.html

Configure Visual Studio 2013 for debugging .NET framework

In order to configure Visual Studio 2013 do the following in the Tools -> Options -> Debugging -> General menu:

  • Disable just my code
  • Disable step over properties and operators
  • Disable require source files to exactly match the original version
  • Enable .NET framework source stepping
  • Enable source server support

配置 Visual Studio 2013 以调试 .NET 框架

为了配置 Visual Studio 2013,请在工具 -> 选项 -> 调试 -> 常规菜单中执行以下操作:

  • 仅禁用我的代码
  • 禁用跳过属性和运算符
  • 禁用要求源文件与原始版本完全匹配
  • 启用 .NET 框架源步进
  • 启用源服务器支持

回答by Mare Infinitus

You can find the reference source here, available for download:

您可以在此处找到参考源,可供下载:

.NET Framework 4.0 Reference source

.NET Framework 4.0 参考源

The sources for WCF, WF, and even the 4.5 Beta / RC and many more can be found there, too:

WCF、WF 甚至 4.5 Beta / RC 的来源也可以在那里找到:

Microsoft Referencesource NetFramework

微软参考源网络框架

回答by nandin

if you want to debug open source code (such as nuget package), you can add this url to your symbol server list

如果你想调试开源代码(比如nuget包),你可以把这个url添加到你的符号服务器列表中

http://srv.symbolsource.org/pdb/Public

http://srv.symbolsource.org/pdb/Public

http://www.symbolsource.org/Public/Home/VisualStudio

http://www.symbolsource.org/Public/Home/VisualStudio