title: How to get a class instance from a Method Base in a StackTrace
body: <p>I would like to provide some helpful message to debug a particular exception and for that I need to access the instances of all the classes of the methods in the stack.</p>
  
  <p>Let's take the following code as an example. Say I have the following class:</p>
  
  <pre><code>Public Class Foo
    Public Name As String
    Public Sub DoStuff(Optional N As Integer = 10)
      If N = 0 Then Throw New Exception("Boom")
      Dim C As New Foo
      C.Name = "Class level =  " &amp; N
      C.DoStuff(N - 1)
    End Sub
  End Class
  </code></pre>
  
  <p>It will cause an exception. What I want to do is to capture the values of Name of all the Foo instances in the stack.</p>
  
  <pre><code>Try
    Dim C As New Foo
    C.Name = "Base class"
    C.DoStuff()
  Catch ex As Exception
    Dim St As New StackTrace(ex)
    For i As Integer = 0 To St.FrameCount - 1
      Dim M = St.GetFrame(i).GetMethod()
      Console.WriteLine(M.Name &amp; " " &amp; M.DeclaringType.ToString)
    Next
  End Try
  </code></pre>
  
  <p>I am almost these, I can get the method and the type of the classes in the call stack, but what I am missing is to be able to get the actual instance in order to be able to access the field Name of each class Foo in the stack.</p>
  
  <p>Is that even possible?</p>
  
  <p>thanks
  Charles</p>