简体   繁体   English

StackTrace文件名未知

[英]StackTrace filename unknown

Something strange is happening in my code where I'm using a StackTrace. 在我使用StackTrace的代码中发生了一些奇怪的事情。 It's almost as if the debug info is not being loaded... but I'm running this on the DEBUG build.The .pdb files are definitelly in the bin directory and up to date. 这几乎就像没有加载调试信息一样......但是我在DEBUG构建中运行它。.pdb文件在bin目录中是最新的并且是最新的。 I've seriously ran out of ideeas : 我已经严重失去了思想:

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"
    }
}

A bit more googling arround found this post 更多谷歌搜索发现这篇文章

Turns out StackTrace has a special constructor 结果StackTrace有一个特殊的构造函数

public StackTrace(bool fNeedFileInfo) 

if you need file info to be populated. 如果您需要填充文件信息。 Ouch 哎哟

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM