Display lines number in Stack Trace for .NET assembly in Release mode

后端 未结 7 1403
生来不讨喜
生来不讨喜 2020-11-22 15:07

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 t

相关标签:
7条回答
  • 2020-11-22 15:31

    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.

    0 讨论(0)
  • 2020-11-22 15:36

    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

    0 讨论(0)
  • 2020-11-22 15:37

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

    0 讨论(0)
  • 2020-11-22 15:39

    Include debug symbols with your build/deployment package.

    0 讨论(0)
  • 2020-11-22 15:43

    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++;
    }
    
    0 讨论(0)
  • 2020-11-22 15:45

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

    0 讨论(0)
提交回复
热议问题