微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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文件构建代码.

原文地址:https://www.jb51.cc/csharp/100912.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐