堆栈跟踪文件名不明 [英] StackTrace filename unknown

查看:99
本文介绍了堆栈跟踪文件名不明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

奇怪的事情在我的code是发生在这里我使用堆栈跟踪。这是几乎一样,如果没有被加载调试信息...但我在bin目录和最新的DEBUG build.The .pdb文件运行此被definitelly。我认真地跑出ideeas的:

 公共类TraceHelper
{
    私有静态的IDictionary<字符串,整数> TraceDictionary =新词典<字符串,整数>();    公共TraceHelper(INT持续时间)
    {         ...
        TraceDictionary [InternalGetCallingLocation()] + =持续时间;
         ...    }
    公共静态字符串InternalGetCallingLocation()
    {
          VAR跟踪=新System.Diagnostics.StackTrace();
          变种帧= trace.GetFrames();
          变种文件名=帧[1] .GetFileName(); //<< - 这始终返回null
          返回帧[0]的ToString(); //这将返回:
          //:行:InternalGetCallingLocation文件偏移量99列<文件名不明> 0:0
    }
}


解决方案

多一点谷歌上搜索发现角落找寻<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/00281bbe-f2ee-488b-8133-74b0095d0c20\">this帖子

原来堆栈跟踪有一个特殊的构造

 公共堆栈跟踪(布尔fNeedFileInfo)

如果你需要文件信息进行填充。哎哟

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

这篇关于堆栈跟踪文件名不明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆