여기 내 목표는 동적으로로드 된 어셈블리에서 스택 추적 정보를 얻는 것입니다. 동적으로로드 된 어셈블리가 호출자에게 오류를 반환하면 스택 추적 정보는 오류가 발생한 동적 어셈블리의 위치를 알려주지 않습니다. 내 예외를 던져 원래 예외를 전달하면 내부 예외로 추가되어 정보가 필요할 것입니다. 새로운 예외를 던지기 위해 모든 동적 어셈블리를 변경하지 않도록 노력하고 있습니다. 누구든지 동적으로로드 된 어셈블리에서 스택 추적 정보를 얻는 더 좋은 방법을 알고 있습니까?동적으로로드 된 스택 추적 정보 얻기
Public Class ErrorPlugin
' Example Function from plug in DLL
Public Function SimpleExample() As Double
Dim RentedUnits As Double = 42
Dim NumberUnits As Double = 0
Try
' Just need to generate exception
Return RentedUnits \ NumberUnits
Catch ex As Exception
' Give's me no Stack Trace infomation.
'Throw
' This will give me Stack Trace infomation,
' but requires adjusting all the plugins.
Throw New Exception("Stop dividing by zero.", ex)
End Try
End Function
End Class
Imports System.Reflection
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rpt As Object
Dim r As Double
Try
rpt = LoadReport("C:\ErrorPlugin\bin\Debug\ErrorPlugin.dll")
r = rpt.SimpleExample()
Catch ex As Exception
MsgBox(ex.Message & vbCrLf & ex.StackTrace)
If ex.InnerException IsNot Nothing Then
MsgBox(ex.InnerException.StackTrace)
End If
End Try
End Sub
Public Function LoadReport(ByVal FileName As String) As Object
Dim m_ReportAssembly As [Assembly]
Dim m_ReportClass As Type
Dim rpt As Object
Try
m_ReportAssembly = Assembly.LoadFrom(FileName)
For Each m_ReportClass In m_ReportAssembly.GetTypes
If m_ReportClass.Name.ToLower = "ErrorPlugin".ToLower Then
rpt = Activator.CreateInstance(m_ReportClass)
Exit For
End If
Next
Return rpt
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
End Class
Throw Ex를 Throw로 변경하고 동일한 결과를 받았습니다. 또한 플러그인에서 예외 처리를 제거하고 동일한 결과를 받았습니다. 그 이유는 모르겠지만 스택 추적을 재설정하는 것으로 보입니까? – Bedwell
이 예제는 프로덕션 환경에있는 일부 코드와 비슷합니다. 오류가 생성되면 웹 서비스에 기록되므로 오류를 검사합니다. 플러그인 (약 200 개)에서 오류가 발생하는 경우 어떤 플러그인이 오류를 생성했는지 알 수 없습니다. 참고 : 플러그인은 오류를 기록하지 않으며, 플러그인을 호출하는 함수는 하나의 중앙 영역에서이를 처리합니다. – Bedwell