[英]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.