如何获得行号(收费)抛出的.NET异常的堆栈跟踪现身 [英] How to get line number(s) in the StackTrace of an exception thrown in .NET to show up

查看:565
本文介绍了如何获得行号(收费)抛出的.NET异常的堆栈跟踪现身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSDN说,这对异常的堆栈跟踪属性类:

MSDN says this about the StackTrace property of the Exception class:

堆栈跟踪属性包含堆栈   跟踪,你可以用它来确定   其中,在C错误的$ C $发生。   堆栈跟踪列出了所有的所谓的   是$ P $方法pceded异常   和源极中的行号   那里的电话发了言。

The StackTrace property holds a stack trace, which you can use to determine where in the code the error occurred. StackTrace lists all the called methods that preceded the exception and the line numbers in the source where the calls were made.

所以我知道这个信息是可用的。我如何获得的行号真正出现在堆栈跟踪?我的code是一个非常困难和复杂的一块code表示经过对象吨抛出一个异常,所以我不想步一个bazillion次,看看那里的例外发生。异常的堆栈跟踪仅显示方法签名,也没有行号。

So I know that this information is available. How do I get the line numbers to actually show up in the stack trace? My code is throwing an exception in a very difficult and complex piece of code that goes through TONS of objects, so I don't want to step through a bazillion times to see where the exception is happening. The stack trace of the exception only shows method signatures and no line numbers.

推荐答案

要获得的行号的堆栈跟踪,你需要有正确的调试信息(PDB文件)旁边的的DLL / EXE文件。为了产生调试信息,设置在选择项目属性 - >构建 - >高级 - >调试信息

To get the line numbers in the StackTrace, you need to have the correct debug information (PDB files) alongside your dlls/exes. To generate the the debug information, set the option in Project Properties -> Build -> Advanced -> Debug Info:

将其设置为完全应该足够了(见的 MSDN文档什么其他的选择呢)。调试信息(即PDB文件)生成调试默认情况下生成配置,但也可以为发行版本配置产生。

Setting it to full should suffice (see the MSDN docs for what the other options do). Debug info (ie. PDB files) are generated for Debug build configurations by default, but can also be generated for Release build configurations.

生成PDBS的发布版本,您可以寄给你没有PDBS code,但下降旁边的dll的PDBS,如果你需要行号(或甚至附加远程调试器)。有一点需要注意的是,在发布版本,行号可能不完全正确的,由于编译器或JIT编译器做的优化(这是尤其如此,如果该行的数字显示为0)。

Generating PDBs for release builds enables you to ship you code without the PDBs, but to drop the PDBs next to the dlls if you need line numbers (or even to attach a remote debugger). One thing to note is that in a release build, the line numbers may not be entirely correct due to optimisations made by the compiler or the JIT compiler (this is especially so if the line numbers show as 0).

这篇关于如何获得行号(收费)抛出的.NET异常的堆栈跟踪现身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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