加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 08:09:14 所属栏目:百科 来源:网络整理
导读:当在Asp.Net网页中抛出异常时,会显示一条错误消息,其中包含完整的堆栈跟踪. 示例如下: Stack Trace: IndexOutOfRangeException: Index was outside the bounds of the array. MyNameSpace.SPAPP.ViewDetailsCodeBehind.LoadView() +5112 MyNameSpace.SPAPP.
当在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文件构建代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读