【问题标题】:StackTrace filename unknownStackTrace 文件名未知
【发布时间】:2009-10-30 14:48:53
【问题描述】:

在我使用 StackTrace 的代码中发生了一些奇怪的事情。就好像调试信息没有被加载......但我在调试版本上运行它。.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"
    }
}

【问题讨论】:

  • 你能显示完整的跟踪吗?需要更多上下文来提供帮助。

标签: c# asp.net reflection stack-trace


【解决方案1】:

找到更多谷歌搜索 this post

原来 StackTrace 有一个特殊的构造函数

public StackTrace(bool fNeedFileInfo) 

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

【讨论】:

    猜你喜欢
    • 2013-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-29
    • 2020-02-16
    • 1970-01-01
    • 2015-06-03
    • 1970-01-01
    相关资源
    最近更新 更多