Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StackTrace filename unknown

Tags:

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"     } } 
like image 539
Radu094 Avatar asked Oct 30 '09 14:10

Radu094


1 Answers

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

like image 76
Radu094 Avatar answered Sep 21 '22 13:09

Radu094