GetILOffset Method

StackFrame.GetILOffset Method

Gets the offset from the start of the Microsoft intermediate language (MSIL) code for the method that is executing. This offset might be an approximation depending on whether the just-in-time (JIT) compiler is generating debugging code or not. The generation of this debugging information is controlled by the DebuggableAttribute.

[Visual Basic]
Public Overridable Function GetILOffset() As Integer
[C#]
public virtual int GetILOffset();
[C++]
public: virtual int GetILOffset();
[JScript]
public function GetILOffset() : int;

Return Value

The offset from the start of the MSIL code for the method that is executing.

Example

[Visual Basic, C#, C++] The following code example demonstrates how you can use the GetILOffset method.

[Visual Basic] 
' Display the stack frame properties.
Dim sf As StackFrame = st.GetFrame(i)
Console.WriteLine(" File: {0}", sf.GetFileName())
Console.WriteLine(" Line Number: {0}", _
   sf.GetFileLineNumber())
' The column number defaults to zero when not initialized.
Console.WriteLine(" Column Number: {0}", _
   sf.GetFileColumnNumber())
If sf.GetILOffset <> StackFrame.OFFSET_UNKNOWN
   Console.WriteLine(" Intermediate Language Offset: {0}", _
       sf.GetILOffset())
End If
If sf.GetNativeOffset <> StackFrame.OFFSET_UNKNOWN
  Console.WriteLine(" Native Offset: {0}", _
      sf.GetNativeOffset())
End If

[C#] 
// Display the stack frame properties.
StackFrame sf = st.GetFrame(i);
Console.WriteLine(" File: {0}", sf.GetFileName());
Console.WriteLine(" Line Number: {0}", 
   sf.GetFileLineNumber());
// Note that the column number defaults to zero
// when not initialized.
Console.WriteLine(" Column Number: {0}", 
   sf.GetFileColumnNumber());
if (sf.GetILOffset() != StackFrame.OFFSET_UNKNOWN)
{
   Console.WriteLine(" Intermediate Language Offset: {0}", 
      sf.GetILOffset());
}
if (sf.GetNativeOffset() != StackFrame.OFFSET_UNKNOWN)
{
   Console.WriteLine(" Native Offset: {0}", 
      sf.GetNativeOffset());
}

[C++] 
// Display the stack frame properties.
StackFrame *sf = st->GetFrame(i);
Console::WriteLine(S" File: {0}", sf->GetFileName());
Console::WriteLine(S" Line Number: {0}", 
   sf->GetFileLineNumber().ToString());
// Note that the column number defaults to zero
// when not initialized.
Console::WriteLine(S" Column Number: {0}", 
   sf->GetFileColumnNumber().ToString());
Console::WriteLine(S" Intermediate Language Offset: {0}", 
   sf->GetILOffset().ToString());
Console::WriteLine(S" Native Offset: {0}", 
   sf->GetNativeOffset().ToString());

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

StackFrame Class | StackFrame Members | System.Diagnostics Namespace | DebuggableAttribute

Show:
© 2016 Microsoft