2009-10-30 3 views
22

Quelque chose d'étrange se passe dans mon code où j'utilise un StackTrace. C'est presque comme si l'information de débogage n'était pas chargée ... mais je cours ceci sur la construction DEBUG. Les fichiers .pdb sont definitelly dans le répertoire bin et à jour. J'ai sérieusement manqué de ideeas:StackTrace filename inconnu

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

Pouvez-vous afficher la trace complète? Besoin de plus de contexte pour aider. – Richard

Répondre

44

Un peu plus googler arround trouvé this post

Il s'avère StackTrace a un constructeur spécial

public StackTrace(bool fNeedFileInfo) 

si vous avez besoin d'informations fichier à être rempli. Ouch

+12

Que diable, c'est plutôt idiot IMO. – kizzx2

+4

FOUL! FAUTE! FAUTE! – FastAl