title: Getting VB.NET line numbers in stack trace
body: <p>I have a VB.NET 2010 Winforms application where I'd like to include line numbers in the stack trace. I've read the following question and answers:</p>
  
  <p><a href="https://stackoverflow.com/questions/5817796/how-to-print-out-line-number-during-application-run-in-vb-net">how to print out line number during application run in VB.net</a></p>
  
  <p>Which mentions "you always need to include the PDB file with your code, which contains debugging information that is used in situations like this". Under advanced compiler settings I've tried "Generate debug info" as "pdb-only" and "full" for my release build and confirmed that a fresh PDB file is generated in the same directory as my EXE. However the following test code generates a line number of zero for each stack frame and doesn't return a filename:</p>
  
  <pre><code>    Dim st As StackTrace = New StackTrace(ex)
      For Each sf As StackFrame In st.GetFrames
          MsgBox("Line " &amp; sf.GetFileLineNumber() &amp; sf.GetFileName)
      Next
  </code></pre>
  
  <p>However the following code straight after it generates an otherwise good looking stack trace so it doesn't seem to be a problem with the exception handler in general:</p>
  
  <pre><code>ExceptionDetails.Text = ex.GetType.ToString &amp; "(0x" &amp; hr.ToString("X8") &amp; "): " &amp; ex.Message &amp; vbCrLf &amp; ex.StackTrace
  </code></pre>
  
  <p>I can't seem to find any other likely settings under the project configuration and wondered if anyone had ideas on other things that may cause this problem. All the solutions I've found searching here and elsewhere just seem to suggest making sure the PDB is in the same path as the executable.</p>