How to get line number(s) in the StackTrace of an exception thrown in .NET to show up

后端 未结 6 1610
醉梦人生
醉梦人生 2020-12-04 21:57

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

The StackTrace property holds a stack trace, which yo

6条回答
  •  攒了一身酷
    2020-12-04 22:22

    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:

    alt text

    Setting it to full should suffice (see the Advanced Build Settings Dialog Box 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.

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

提交回复
热议问题