在我使用StackTrace的代码中发生了一些奇怪的事情。这几乎就像没有加载调试信息一样......但是我在DEBUG构建中运行它。.pdb文件在bin目录中是最新的并且是最新的。我已经严重失去了想法:
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"
}
}
答案 0 :(得分:49)