StackTrace文件名未知

在我使用StackTrace的代码中发生了一些奇怪的事情。 这几乎就像没有加载调试信息一样……但是我在DEBUG构建中运行它。.pdb文件在bin目录中是最新的并且是最新的。 我已经严重失去了思想:

public class TraceHelper { private static IDictionary TraceDictionary = new Dictionary(); 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 :0:0" } } 

谷歌搜索了一下这篇文章

结果StackTrace有一个特殊的构造函数

 public StackTrace(bool fNeedFileInfo) 

如果您需要填充文件信息。 哎哟