C# 获取与Visual Studio中显示的堆栈跟踪相同的堆栈跟踪';s";调用堆栈“;窗口

C# 获取与Visual Studio中显示的堆栈跟踪相同的堆栈跟踪';s";调用堆栈“;窗口,c#,.net,debugging,callstack,diagnostics,C#,.net,Debugging,Callstack,Diagnostics,还是过时 var newStackTrace = new StackTrace(true); 给我一个StackTrace,它与我在VisualStudioPro的“调用堆栈”窗口中看到的不同。当前线程的ManagedId与我在“Threads”窗口中选择的相同。值得一提的是,我正在运行带有pdb文件的调试版本,并且源代码与程序集匹配 Visual Studio从何处获取其调用堆栈?与Visual Studio相比,是什么导致System.Diagnostics.StackTrace为同一线程

还是过时

var newStackTrace = new StackTrace(true);
给我一个StackTrace,它与我在VisualStudioPro的“调用堆栈”窗口中看到的不同。当前线程的ManagedId与我在“Threads”窗口中选择的相同。值得一提的是,我正在运行带有pdb文件的调试版本,并且源代码与程序集匹配

Visual Studio从何处获取其调用堆栈?与Visual Studio相比,是什么导致System.Diagnostics.StackTrace为同一线程返回不同的StackTrace

我已经读到堆栈跟踪是不可靠的,但是如果我能得到与VS相同的跟踪,那对我来说就足够了

更新1: 来自VS的堆栈跟踪:

var newStackTrace = new StackTrace(Thread.CurrentThread, true);
对于在IIS上运行的大型复杂应用程序,它非常不同(不同的堆栈帧、行号),对于下面列出的程序,只有行号不同:

   at A.X.BORD.ActivateDebugger(Object sender, ActivateDebuggerEventArgs args) in X:\trunk\Source\S.X.BORD.cs:line 1865
   at A.X.BOHost.Debug(Object o, Int32 line) in X:\trunk\Source\S.X.BOHost.cs:line 259
   at System.Docu.File.DFF.LoadImage(Object sender, LoadImageEventArgs args) in SCRIPTFILE:line 24
   at A.N.WC.PB.LoadImageAsync(Stream outputStream) in X:\trunk\Source.N.WC\PB.cs:line 137
   at A.C.W.GIAB(JSObject args, JSObject result) in X:\trunk\Source.C.W.cs:line 452
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at A.N.CM.AIS.Invoke(MethodInfo method, Object target, JSObject[] args) in X:\trunk\Source.N.CM\AIS.cs:line 173
   at A.C.W.ProcessRequest(HttpContext context, NameValueCollection responseHeader) in X:\trunk\Source.C.W.cs:line 210
   at A.N.Http.HTTPH.ExecuteHandler(HttpContext context, String ashx, NameValueCollection responseHeader) in X:\trunk\Source.N.Http\HTTPH.cs:line 471
   at A.N.Http.HTTPH.ProcessDefaultRequest(HttpContext context, NameValueCollection responseHeader) in X:\trunk\Source.N.Http\HTTPH.cs:line 165
   at A.N.Http.HTTPH.ProcessRequest(HttpContext context, NameValueCollection responseHeader) in X:\trunk\Source.N.Http\HTTPH.cs:line 374
   at HandlerModule.Application_AuthenticateRequest(Object sender, EventArgs e) in X:\trunk\www\WAS\App_Code\HandlerModule.cs:line 92
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
   at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
   at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)
   at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
   at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
   at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
更新2 一旦考虑到“托管到本机/本机到托管转换”位,并且忽略格式设置(混淆堆栈在这里帮助了我:-),堆栈基本上是相同的,除了从顶部开始的第三帧;报告“System.Docu.File.DFF”的文件。System.Docu.File.DFF.dll是我们通过反射从用户“伪代码”生成的程序集


我很高兴StackTrace找到了方法名/行,并混淆了VS没有。。。这就是我需要帮助的地方。

你能不能加入到你的参考资料的链接,上面说堆栈跟踪不可靠?是不是你没有检查所有的帧(即
stacktrace.GetFrames()
)。请举例说明你的堆栈跟踪与VS的不同之处。也不清楚你是在哪里使用VS来比较代码示例中的两个。@RufusL我刚刚读到Eric Lippert的一些东西。@RufusL我附加了(模糊化)堆栈跟踪。我只是在某个任意断点上突破。
   at A.X.BORD.ActivateDebugger(Object sender, ActivateDebuggerEventArgs args) in X:\trunk\Source\S.X.BORD.cs:line 1865
   at A.X.BOHost.Debug(Object o, Int32 line) in X:\trunk\Source\S.X.BOHost.cs:line 259
   at System.Docu.File.DFF.LoadImage(Object sender, LoadImageEventArgs args) in SCRIPTFILE:line 24
   at A.N.WC.PB.LoadImageAsync(Stream outputStream) in X:\trunk\Source.N.WC\PB.cs:line 137
   at A.C.W.GIAB(JSObject args, JSObject result) in X:\trunk\Source.C.W.cs:line 452
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at A.N.CM.AIS.Invoke(MethodInfo method, Object target, JSObject[] args) in X:\trunk\Source.N.CM\AIS.cs:line 173
   at A.C.W.ProcessRequest(HttpContext context, NameValueCollection responseHeader) in X:\trunk\Source.C.W.cs:line 210
   at A.N.Http.HTTPH.ExecuteHandler(HttpContext context, String ashx, NameValueCollection responseHeader) in X:\trunk\Source.N.Http\HTTPH.cs:line 471
   at A.N.Http.HTTPH.ProcessDefaultRequest(HttpContext context, NameValueCollection responseHeader) in X:\trunk\Source.N.Http\HTTPH.cs:line 165
   at A.N.Http.HTTPH.ProcessRequest(HttpContext context, NameValueCollection responseHeader) in X:\trunk\Source.N.Http\HTTPH.cs:line 374
   at HandlerModule.Application_AuthenticateRequest(Object sender, EventArgs e) in X:\trunk\www\WAS\App_Code\HandlerModule.cs:line 92
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
   at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
   at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)
   at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
   at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
   at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
namespace stacktrace
{
    class Program
    {
        static void Main(string[] args)
        {
            var stacktrace = new System.Diagnostics.StackTrace(true);
        }
    }
}