简体   繁体   中英

StackTrace filename unknown

Something strange is happening in my code where I'm using a 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. 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

public StackTrace(bool fNeedFileInfo) 

if you need file info to be populated. Ouch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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