[英]Visual Studio Debugger not stepping into .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;
}
}
}
我跟着Reflector中的調用,直到代碼調用System.Net.WebClient.DownloadBits
方法為止。 如果調用是異步執行的,則此方法通過調用System.Net.WebRequest
類上的異步編程模型(APM)方法BeginGetResponse
,進一步調度線程池線程上的工作。
這是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;
}
所以,我在Visual Studio中設置了兩個斷點:
1) Sytem.Net.WebClient.DownloadBits
方法中的一個; 和另一個
2)在System.Net.WebRequest.BeginGetResponse
方法上。
我仔細檢查了以下內容。
1)我在Visual Studio工具 - >選項對話框中正確配置了調試設置,允許調試器逐步執行.NET框架源。
2)我已經啟用了將調試符號下載和緩存到適當的位置。
3)我仔細檢查了位置,發現我的代碼引用的所有程序集都有Debug符號,特別是對於具有我的斷點設置方法的System.dll
。
但是,當我運行調試代碼時,它抱怨它無法找到System.dll
的調試符號。 因此,我單擊“加載”按鈕,讓它在運行時從Microsoft Symbol Server下載它們。
即便如此,雖然它確實在DownloadBits
方法中出現了問題,正如我在調用堆棧窗口中看到的那樣,以及在設置斷點時我要求它打印的輸出窗口中打印的消息,它沒有顯示或進入該方法的來源。
我在“ 調用堆棧”窗口中右鍵單擊了DownloadBits
方法的堆棧框,單擊“ 加載符號”菜單項,但它不在那里。 因此,還禁用了“ 轉到源代碼”菜單項。
我清除了緩存,讓它重新下載所有程序集,但這也沒有幫助。
我正在使用Visual Studio Community Edition 2015,我的程序是針對.NET框架的v4.5.2,我之前已經能夠使用此設置多次進入.NET源程序集。
我錯過了什么?
您可以嘗試使用dotPeek的即時Symbol服務器。 它將反編譯程序集並充當普通的Symbol Server。
在dotPeek中設置符號服務器(工具 - >符號服務器)。 將符號服務器地址復制到剪貼板。
將此符號服務器添加到Visual Studio並刪除另一個(或者只是禁用它)。
請注意,加載所有.NET程序集可能需要很長時間。 您可以通過選擇dotPeek Assemblies opened in the Assembly Explorer
選項中Assemblies opened in the Assembly Explorer
來調整它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.