Getting current file name and Line number

P

pukya78

Hi,
I am trying to get the current file and the line number which is
getting executed. I used:

MessageBox.Show(New StackTrace(New
StackFrame(True)).GetFrame(0).GetFileLineNumber) which gives me the
line number.

Later on, I was trying to write a generalized routine, so that I can
log the file name and the method.

<code>
Public Function MeAndMyCaller As String
Dim CurrentStack As New System.Diagnostics.StackTrace
Dim Myself As String = CurrentStack.GetFrame(0).GetMethod.Name
Dim MyCaller As String = CurrentStack.GetFrame(1).GetMethod.Name
Dim cur_file As String = CurrentStack.GetFrame(1).GetFileName
Dim line_num As Integer = CurrentStack.GetFrame(1).GetFileLineNumber
Return "In " & Myself & vbCrLf & "Called by " & MyCaller
End Function
</code>

Here, I get MyCaller correctly, but cur_file is not getting returned. I
get a Null exception. line_num is returned as 0, all the time.

What am I doing wrong? Any suggestions/ideas?

Regards,
P
 
G

Guest

I am trying to get the current file and the line number which is
getting executed. I used: ....
Here, I get MyCaller correctly, but cur_file is not getting returned. I
get a Null exception. line_num is returned as 0, all the time.

Your symptoms are consistent with debug vs release configurations. Line
number is available in debug version, not available in release version.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top