title: Preventing JIT inlining on a method
body: <p>I've got sort of a unique situation.  I've been working on an open source library for sending email.  In this library, I need a reliable way to get the calling method.  I've done this with a <code>StackTrace</code> by analyzing the <code>StackFrame</code> objects inside it.  This works without issue in a debug-mode project where optimizations are turned off.</p>
  
  <p>The problem occurs when I switch to release mode where optimizations are turned on.  The stack trace looks like this:</p>
  
  <pre><code>&gt; FindActionName at offset 66 in file:line:column &lt;filename unknown&gt;:0:0
  &gt; Email at offset 296 in file:line:column &lt;filename unknown&gt;:0:0
  &gt; CallingEmailFromRealControllerShouldFindMailersActionName at offset 184
       in file:line:column &lt;filename unknown&gt;:0:0
  &gt; _InvokeMethodFast at offset 0 in file:line:column &lt;filename unknown&gt;:0:0
  &gt; InvokeMethodFast at offset 152 in file:line:column &lt;filename unknown&gt;:0:0
  ...
  </code></pre>
  
  <p>This is taken from a failing unit test.  In line 3 of this trace, I should see a method called <code>TestEmail</code> which is defined elsewhere, but I believe the JITter is inlining it.  I've read that you can prevent inlining by making a method virtual, but this doesn't work.  Does anyone know of a reliable method for preventing method inlining so your method will show up in a stack trace?</p>