问题很明显。 它应该与如何获得线路例外
StackTrace st = new StackTrace(exc, true);
//Get the first stack frame
StackFrame frame = st.GetFrame(0);
//Get the file name
//string fileName = frame.GetFileName();
//Get the line number from the stack frame
int line = frame.GetFileLineNumber();
问题的工作是,如果我启动我在调试模式下的应用程序它工作始终。 当我在发布模式下启动它时,似乎需要使用pdb文件来获取此信息。那么保留pdb文件有什么缺点(我认为只有在调试模式下才需要它们)。 Viceversa是获取异常信息的唯一方法吗?
编译器会重新安排您的所有代码并完全删除一些行 - 释放模式会大量优化代码,并且输出“代码”可能与您的原始代码无关。堆栈跟踪不会在“发布”中显示行号,因为根据通常单独的exe(或dll)无法分辨。 –
但是,如果我保留pdb文件堆栈跟踪确实显示行号。 – Patrick
@Benjamin:您可以在发布模式下获得行号。但是,由于你提到的原因,它们可能不是100%准确的。 – sstan