c# – 错误行号的异常错误消息

当在Asp.Net网页中抛出异常时,会显示一条错误消息,其中包含完整的堆栈跟踪.

示例如下:

Stack Trace:
IndexOutOfRangeException: Index was outside the bounds of the array.

MyNameSpace.SPAPP.ViewDetailsCodeBehind.LoadView() +5112
MyNameSpace.SPAPP.ViewDetailsCodeBehind.Page_Load(Object sender,EventArgs e) +67
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,Object o,Object t,EventArgs e) +13
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs e) +43
System.Web.UI.Control.OnLoad(EventArgs e) +98
… …

问题是显示的行号与我的代码中引发异常的行不对应.
在上面的例子中,堆栈显示行号5111,但我的.cs文件后面的代码只有250行!

aspx页面存储在SharePoint站点中,带有代码的程序集已部署到GAC.另外,我已经在Debug模式下编译了.
鉴于上面的设置,我如何找出代码中的哪一行导致异常?

strelokstrelok指出的澄清:

In Release mode the number in front of the exception is NOT the line of code. Instead it’s an offset to the native compiled code,which doesn’t have any meaning to humans. More about this here: 07001

In debug mode the PDB file will automatically map the native code offset to your .cs line in code and the number displayed WILL be the corresponding line in code.

解决方法

这些数字不是行号.在发布模式下,堆栈跟踪包含本机编译代码的偏移量而不是行号.你可以在这里阅读更多相关信息:
http://odetocode.com/Blogs/scott/archive/2005/01/24/963.aspx

在堆栈跟踪中获取行号的唯一方法是在调试模式下使用PDB文件构建代码.

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...