如何获得行号(收费)抛出的.NET异常的堆栈跟踪现身行号、堆栈、抛出、如何获得

由网友(温柔小女人)分享简介:MSDN说,这对异常的堆栈跟踪属性类:MSDN says this about the StackTrace property of the Exception class:堆栈跟踪属性包含堆栈跟踪,你可以用它来确定其中,在C错误的$ C $发生。堆栈跟踪列出了所有的所谓的是$ P $方法pceded异常和源极中...

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).

阅读全文

相关推荐

最新文章