行号不正确的异常错误消息 [英] Exception error message with incorrect line number

查看:35
本文介绍了行号不正确的异常错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When an exception is thrown in an Asp.Net web page, an error message is displayed with the complete stack trace.

示例如下:

堆栈跟踪:
IndexOutOfRangeException: 索引超出数组范围.

MyNameSpace.SPAPP.ViewDetailsCodeBehind.LoadView() +5112MyNameSpace.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
……

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 行!

The problem is that the Line number displayed does not correspond to the line in my code that originated the exception.
In the example above, the stack shows line number 5111, yet my code behind .cs file only has 250 lines!

aspx 页面存储在 SharePoint 站点中,并且带有代码的程序集已部署到 GAC.另外,我在调试模式下编译.

根据上述设置,我如何找出代码中的哪一行导致了异常?

The aspx page is stored in a SharePoint site and the Assembly with the code behind has been deployed to GAC. Also, I've compiled in Debug mode.

Given the settings above, how can I find out what line in my code caused the Exception?



strelokstrelok所指出的澄清:



Clarification as pointed out by strelokstrelok:

发布模式中,异常前面的数字不是代码行.相反,它是对本机编译代码的偏移,这对人类没有任何意义.更多关于这里:http://odetocode.com/Blogs/scott/archive/2005/01/24/963.aspx

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: http://odetocode.com/Blogs/scott/archive/2005/01/24/963.aspx

调试模式下,PDB 文件会自动将本机代码偏移量映射到代码中的 .cs 行,并且显示的数字将是代码中的相应行.

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

Those numbers are NOT line numbers. In Release mode the stack trace contains the offsets into the native compiled code instead of line numbers. You can read some more about it here: http://odetocode.com/Blogs/scott/archive/2005/01/24/963.aspx

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

The only way to get line numbers in a stack trace is if you built you code in debug mode with the PDB files available.

这篇关于行号不正确的异常错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆