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

后端 未结 7 1493
生来不讨喜
生来不讨喜 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: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++;
    }
    

提交回复
热议问题