我正在.NET 6框架下编译(我还在Visual中试用了.NET Core3.1) C#代码
虽然它在Windows环境下运行得非常好,但使用相同的选项,我无法在Linux (Ubuntu18.04)下获得异常的StackTrace中的行号。
present
发布于 2021-12-14 02:41:10
试试这个方法。当我需要错误发生的行号时,我写了它。
''' <summary>
'''
''' </summary>
''' <param name="ex"></param>
Public Sub ErrorShow(ByVal ex As Exception)
Dim Result As String
Dim hr As Integer = Runtime.InteropServices.Marshal.GetHRForException(ex)
Result = ex.GetType.ToString & "(0x" & hr.ToString("X8") & "): " & ex.Message & Environment.NewLine & ex.StackTrace & Environment.NewLine
Dim st As StackTrace = New StackTrace(ex, True)
For Each sf As StackFrame In st.GetFrames
If sf.GetFileLineNumber() > 0 Then
Result &= "Line:" & sf.GetFileLineNumber() & " Filename: " & IO.Path.GetFileName(sf.GetFileName) & Environment.NewLine
End If
Next
Console.WriteLine(Result)
End Subhttps://stackoverflow.com/questions/70342548
复制相似问题