2009-10-30 72 views
22

在我使用StackTrace的代碼中發生了一些奇怪的事情。這幾乎就好像調試信息沒有被加載......但我在DEBUG build上運行這個.pdb文件在bin目錄中是definitelly並且是最新的。我認真地跑出ideeas的:StackTrace文件名未知

public class TraceHelper 
{ 
    private static IDictionary<string,int> TraceDictionary = new Dictionary<string,int>(); 

    public TraceHelper(int duration) 
    { 

     ... 
     TraceDictionary[InternalGetCallingLocation()]+=duration; 
     ... 

    } 
    public static string InternalGetCallingLocation() 
    { 
      var trace = new System.Diagnostics.StackTrace(); 
      var frames = trace.GetFrames(); 
      var filename = frames[1].GetFileName(); //<<-- this always returns null 
      return frames[0].ToString(); //this returns: 
      // "InternalGetCallingLocation at offset 99 in file:line:column <filename unknown>:0:0" 
    } 
} 
+1

你能顯示完整的跟蹤嗎?需要更多的上下文來幫助。 – Richard 2009-10-30 16:40:05

回答

44

多一點谷歌上搜索發現角落找尋this post

原來堆棧跟蹤有一個特殊的構造

public StackTrace(bool fNeedFileInfo) 

,如果你需要文件信息進行填充。 Ouch

+12

什麼,這是相當愚蠢的國際海事組織。 – kizzx2 2011-05-18 16:25:52

+4

FOUL!犯規!犯規! – FastAl 2013-08-06 18:51:28