在发布模式下显示 .NET 程序集的堆栈跟踪中的行号

发布于 2024-07-14 23:24:19 字数 286 浏览 7 评论 0原文

有没有办法在发布模式下显示 .NET 程序集构建/部署的堆栈跟踪中的行?

更新:

我的应用程序分为三个类库项目和一个 ASP.NET“网站”项目。 我试图追踪的错误位于三个类库项目之一中。 我只为生成“对象引用未设置到对象实例”错误的类库项目部署了 pdb 文件。

行号仍然没有显示在堆栈跟踪中。 我是否需要为所有项目部署 pdb 文件才能获取堆栈跟踪中的行号?

工作解决方案

为每个应用程序部署 pdb 文件修复了行号问题。

Is there a way to display the lines in the stack trace for the .NET assembly build/deployed in Release mode?

UPDATE:

My application is divided into three class library projects and one ASP.NET "website" project. The error I am trying to track down is in one of the three class library projects. I only deployed the pdb file for the class library project that is generating the "Object reference not set to an instance of an object" error.

The line numbers are still not showing up in the stack trace. Do I need to deploy the pdb files for all projects to get the line numbers in the stack trace?

Working solution

Deploying the pdb file for each application fixed the line number issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

太阳哥哥 2024-07-21 23:24:19
  • 进入要查看堆栈跟踪行号的项目的“属性”窗口。
  • 单击构建“垂直选项卡”。
  • 选择“发布”配置。 检查 DEBUG 常量参数。
  • 取消选中“优化代码”参数以避免内联代码偶尔出现的跟踪问题(此步骤不是必需的)。
  • 按高级...按钮并选择输出 -> 调试信息-> 仅限 pdb。
  • 使用程序集部署生成的 .pdb 文件。

使用下面的注释实现:

  • 另一件事要检查的是“打包/发布 Web”部分中的“排除生成的调试符号”复选框也未选中
  • Go into the Properties window for the project where you want to see stack trace line numbers.
  • Click on the Build "vertical tab".
  • Select "Release" configuration. Check the DEBUG constant parameter.
  • Uncheck the "Optimize code" parameter to avoid the occasional trace issue with inlined code (this step is not essential).
  • Press the Advanced... button and choose Output -> Debug Info -> pdb-only.
  • Deploy the generated .pdb file with the assembly.

Implemented with the comment below:

  • One other thing to check is in the "Package/Publish Web" section that the "Exclude generated debug symbols" checkbox is also unchecked
萌吟 2024-07-21 23:24:19

在 VS2012 中,您还需要在属性的“打包/发布 Web”部分中取消选中“排除生成的调试符号”。

In VS2012 you need to uncheck "Exclude generated debug symbols" in the Package/Publish Web section of the properties as well.

兲鉂ぱ嘚淚 2024-07-21 23:24:19

我的解决方案

将 pdb 文件复制到可执行文件的同一文件夹中。

现在我可以在运行exe文件时查看行号。

这就是

http://msdn.microsoft 的原因。 com/en-us/library/ee416588%28v=vs.85%29.aspx

My solution

Copy pdb file in same folder that executable file.

now i can view the line number when run the exe file.

this is reason

http://msdn.microsoft.com/en-us/library/ee416588%28v=vs.85%29.aspx

如梦 2024-07-21 23:24:19

我过去遇到过一些问题,我觉得需要使用发布版本来部署 PDB 文件才能跟踪错误。 原因是,就像你说的,异常发生在一个非常大的方法中,我无法准确地确定它发生在哪里。

这可能表明该方法需要重构为更小、更细粒度的方法。 没有一个万能的答案,但这种方法在短期内(我经常在重构过程中发现错误)和长期来看都对我很有帮助。

只是一个想法。

I've run into problems in the past where I feel the need to deploy PDB files with a release build in order to track down an error. The reason is, like you said, was that the exception occurred in a method that was very large and I could not accurately pinpoint where it was happening.

This might be an indication that the method needs to be refactored into smaller, more granular methods. Not a one size fits all answer, but this approach has served me well in the short term (I've often found the bug during the refactoring) and in the long run.

Just a thought.

似梦非梦 2024-07-21 23:24:19

在构建/部署包中包含调试符号。

Include debug symbols with your build/deployment package.

○闲身 2024-07-21 23:24:19

在 VS 2008 Express 中,我在“项目属性”下找到了它 --> 编译--> 高级编译选项。

In VS 2008 Express, I found it under Project Properties --> Compile --> Advanced Compile Options.

莳間冲淡了誓言ζ 2024-07-21 23:24:19

在 .NET Core 中,您需要关闭发布模式的“优化代码”选项才能显示正确的行号。

控制代码的 C# 编译器选项一代

In .NET Core you need to turn off 'Optimize code' option for release mode to show the correct line number.

C# Compiler Options that control code generation

空城仅有旧梦在 2024-07-21 23:24:19

这每次都有效。 您只需对堆栈跟踪消息进行子字符串化即可。 真的很简单! 另外,在 vb.net 中,您确实需要执行“显示所​​有文件”并包含 pdb。

'Err is the exception passed to this function

Dim lineGrab As String = err.StackTrace.Substring(err.StackTrace.Length - 5)
Dim i As Integer = 0
While i < lineGrab.Length                   
    If (IsNumeric(lineGrab(i))) Then
        lineNo.Append(lineGrab(i))
    End If
    i += 1
End While

'LineNo holds the number as a string

C# 版本:

string lineGrab = error.StackTrace.Substring(error.StackTrace.Length - 5);

int i = 0;
int value;
while (i < lineGrab.Length)
{
    if (int.TryParse(lineGrab[i].ToString(), out value))
    {
        strLineNo.Append(lineGrab[i]);
    }
    i++;
}

This works every time. You just need to substring the stack trace message. Real Easy! Also, in vb.net you do need to do the "Show All Files" and include the pdb.

'Err is the exception passed to this function

Dim lineGrab As String = err.StackTrace.Substring(err.StackTrace.Length - 5)
Dim i As Integer = 0
While i < lineGrab.Length                   
    If (IsNumeric(lineGrab(i))) Then
        lineNo.Append(lineGrab(i))
    End If
    i += 1
End While

'LineNo holds the number as a string

C# version:

string lineGrab = error.StackTrace.Substring(error.StackTrace.Length - 5);

int i = 0;
int value;
while (i < lineGrab.Length)
{
    if (int.TryParse(lineGrab[i].ToString(), out value))
    {
        strLineNo.Append(lineGrab[i]);
    }
    i++;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文