简体   繁体   English

Visual Studio Debugger没有进入.NET框架源代码

[英]Visual Studio Debugger not stepping into .NET framework source code

I have this simple async call I am making. 我正在进行这个简单的异步调用。 I want to follow the call to the DownloadDataTaskAsync method and step through into the Microsoft .NET framework source code. 我想跟随对DownloadDataTaskAsync方法的调用,并逐步进入Microsoft .NET框架源代码。

using System;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace WhereIsTheTaskSchedulerHere
{
    class Program
    {
        static void Main(string[] args)
        {
            var task = GetData("http://sathyaish.net");
            var buffer = task.Result;

            var data = Encoding.ASCII.GetString(buffer);

            Console.WriteLine(data);
            Console.WriteLine("\nPress any key to continue...");
            Console.ReadKey();
        }

        async static Task<byte[]> GetData(string url)
        {
            var client = new WebClient();
            var data = await client.DownloadDataTaskAsync(url);
            return data;
        }
    }
}

I followed the call in Reflector until the point that the code calls System.Net.WebClient.DownloadBits method. 我跟着Reflector中的调用,直到代码调用System.Net.WebClient.DownloadBits方法为止。 If the call was meant to be executed asynchronously, this method further schedules the work on a threadpool thread by calling the Asynchronous Programming Model (APM) method BeginGetResponse on the System.Net.WebRequest class. 如果调用是异步执行的,则此方法通过调用System.Net.WebRequest类上的异步编程模型(APM)方法BeginGetResponse ,进一步调度线程池线程上的工作。

Here is the code of the DownloadBits method from Reflector. 这是Reflector的DownloadBits方法的代码。

private byte[] DownloadBits(WebRequest request, Stream writeStream, CompletionDelegate completionDelegate, AsyncOperation asyncOp)
{
    WebResponse response = null;
    DownloadBitsState state = new DownloadBitsState(request, writeStream, completionDelegate, asyncOp, this.m_Progress, this);
    if (state.Async)
    {
        request.BeginGetResponse(new AsyncCallback(WebClient.DownloadBitsResponseCallback), state);
        return null;
    }
    response = this.m_WebResponse = this.GetWebResponse(request);
    int bytesRetrieved = state.SetResponse(response);
    while (!state.RetrieveBytes(ref bytesRetrieved))
    {
    }
    state.Close();
    return state.InnerBuffer;
}

So, I set up two breakpoints in Visual Studio: 所以,我在Visual Studio中设置了两个断点:

1) One on the Sytem.Net.WebClient.DownloadBits method; 1) Sytem.Net.WebClient.DownloadBits方法中的一个; and the other 和另一个

在此输入图像描述

2) On the System.Net.WebRequest.BeginGetResponse method. 2)在System.Net.WebRequest.BeginGetResponse方法上。

在此输入图像描述

在此输入图像描述

I double-checked the following. 我仔细检查了以下内容。

1) That I configured the Debugging settings in the Visual Studio Tools -> Options dialog correctly allowing the debugger to step through .NET framework source. 1)我在Visual Studio工具 - >选项对话框中正确配置了调试设置,允许调试器逐步执行.NET框架源。

在此输入图像描述

2) That I had enabled the downloading and caching of debug symbols to a proper location. 2)我已经启用了将调试符号下载和缓存到适当的位置。

在此输入图像描述

3) I double-checked the location and saw that there were Debug symbols for all the assemblies my code referenced and particularly for the System.dll which had the methods that my breakpoints were set on. 3)我仔细检查了位置,发现我的代码引用的所有程序集都有Debug符号,特别是对于具有我的断点设置方法的System.dll

在此输入图像描述

However, when I ran the code with debugging on, it complained that it couldn't find the debug symbols for System.dll . 但是,当我运行调试代码时,它抱怨它无法找到System.dll的调试符号。 So, I clicked the Load button to let it download them at runtime from the Microsoft Symbol Server. 因此,我单击“加载”按钮,让它在运行时从Microsoft Symbol Server下载它们。

在此输入图像描述

Even then, while it did break at the DownloadBits method, as I saw from the Call Stack Window and from the message it printed in the Output Window that I had asked it to print while setting up the breakpoint, it did not show or step into the source of that method. 即便如此,虽然它确实在DownloadBits方法中出现了问题,正如我在调用堆栈窗口中看到的那样,以及在设置断点时我要求它打印的输出窗口中打印的消息,它没有显示或进入该方法的来源。

在此输入图像描述

I right-clicked the stack-frame of the DownloadBits method in the Call Stack Window to click the Load Symbols menu item, but it wasn't there. 我在“ 调用堆栈”窗口中右键单击了DownloadBits方法的堆栈框,单击“ 加载符号”菜单项,但它不在那里。 Consequently, the Go to Source Code menu item was also disabled. 因此,还禁用了“ 转到源代码”菜单项。

在此输入图像描述

I cleared the cache and let it download all assemblies afresh but that hasn't helped either. 我清除了缓存,让它重新下载所有程序集,但这也没有帮助。

I am using Visual Studio Community Edition 2015 and my program is targeting v4.5.2 of the .NET framework and I have previously been able to step into .NET source assemblies using this set up many times. 我正在使用Visual Studio Community Edition 2015,我的程序是针对.NET框架的v4.5.2,我之前已经能够使用此设置多次进入.NET源程序集。

What have I been missing? 我错过了什么?

You can try to use an on-the-fly Symbol Server with dotPeek . 您可以尝试使用dotPeek的即时Symbol服务器。 It will decompile the assemblies and act as a normal Symbol Server. 它将反编译程序集并充当普通的Symbol Server。

Setup the symbol server in dotPeek (Tools -> Symbol Server). 在dotPeek中设置符号服务器(工具 - >符号服务器)。 Copy the Symbol Server address to the clipboard. 将符号服务器地址复制到剪贴板。

Add this Symbol Server to Visual Studio and remove the other one (or just disable it). 将此符号服务器添加到Visual Studio并删除另一个(或者只是禁用它)。

Be aware, it can take a long time to load all .NET assemblies. 请注意,加载所有.NET程序集可能需要很长时间。 You can tweak it by choosing Assemblies opened in the Assembly Explorer option in dotPeek. 您可以通过选择dotPeek Assemblies opened in the Assembly Explorer选项中Assemblies opened in the Assembly Explorer来调整它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio源代码步进 - visual studio source stepping Visual Studio 调试器进入 azure 函数项目上的非用户代码 - Visual Studio debugger stepping into non user code on azure functions projects System.Linq的Visual Studio .Net源代码步进 - Visual Studio .Net source stepping for System.Linq Visual Studio调试器未进入服务层 - Visual studio debugger not stepping into service layer 进入 .NET 框架代码时源文件不匹配 - Source files mismatch when stepping into .NET Framework code 在Visual Studio 2012中调试.NET Framework源代码? - Debug .NET Framework Source Code in Visual Studio 2012? 进入调试器时,Visual Studio 2008,Excel加载项挂起 - Visual Studio 2008, excel add-in hangs when stepping in debugger 如何在Visual Studio 2017中调试.NET 4.6框架源代码? - How do I debug .NET 4.6 framework source code in Visual Studio 2017? 使用.Net Framework v4.8和Visual Studio 2019查询TFS 2015源代码存储库DateTime属性 - Querying TFS 2015 Source Code Repository DateTime Properties with .Net Framework v4.8 and Visual Studio 2019 Debug .NET Framework的源代码仅显示Visual Studio 2010中的反汇编 - Debug .NET Framework's source code only shows disassembly in Visual Studio 2010
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM