Bug 3289 - GetILOffset always returns 0 (zero)
Summary: GetILOffset always returns 0 (zero)
Alias: None
Product: Runtime
Classification: Mono
Component: Debugger ()
Version: unspecified
Hardware: PC Windows
: Low normal
Target Milestone: ---
Assignee: Zoltan Varga
Depends on:
Reported: 2012-02-09 04:48 UTC by Michal
Modified: 2017-07-11 22:11 UTC (History)
6 users (show)

Tags: XATriaged
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Michal 2012-02-09 04:48:11 UTC
System.Diagnostics.StackFrame.GetILOffset always returns 0 (zero).

Sample code:
private static void GetStackTrace(this Exception exception, StringBuilder output)
  var stackTrace = new StringBuilder();
  var st = new System.Diagnostics.StackTrace(exception);

  foreach (var sf in st.GetFrames())
   var method = sf.GetMethod();

   var parameters = new StringBuilder();
   foreach (var p in method.GetParameters())
    parameters.AppendFormat("{0}, ", p);
   if (parameters.Length > 0)
    parameters.Remove(parameters.Length - 2, 2);

   stackTrace.Insert(0, String.Format("at {0}.{1}({2}) [0x{3:x8}]\n",
    method.ReflectedType.FullName, method.Name, parameters, sf.GetILOffset()));

Comment 1 Rodrigo Kumpera 2017-07-11 22:11:40 UTC
This is by design, you must compile and run with debug enabled.