title: AddRef on IUnknown(IXRApplication) crashing
body: <p>I am debugging a larger issue but I have narrowed down to a specific scenario.<br>
  Firstly:</p>
  
  <pre><code>XamlRuntimeInitialize();
  
  IXRApplication* pApp;
  res=GetXRApplicationInstance(&amp;pApp);
  </code></pre>
  
  <p>This works fine, Then:</p>
  
  <pre><code>IUnknown* pUnk;
  res=pApp-&gt;QueryInterface(IID_IUnknown, (void**)&amp;pUnk);
  </code></pre>
  
  <p>This executes and even returns <code>S_OK</code> however the address returned in <code>pUnk</code> is not the same as <code>pApp</code>(exactly 4bytes less), unexpected but technically not an issue</p>
  
  <p>After That:</p>
  
  <pre><code>UINT cnt=pUnk-&gt;AddRef();
  </code></pre>
  
  <p>This executes and returns 0 but from this point on if I try to call <code>pUnk-&gt;Release</code> or <code>pUnk-&gt;QueryInterface</code> it crashes.  If I call <code>pUnk-&gt;Release</code> before <code>pUnk-AddRef</code> it runs but again after <code>pUnk-&gt;AddRef</code> any call crashes.  It seems as though the <code>AddRef</code> is actually destroying the object.  The crash appears to be a null reference exception.  </p>
  
  <p><strong><em>EDIT:</em></strong></p>
  
  <p>So after learning how to debug on a WEC7 Emulator I have found what looks like the issue. The assembly for <code>AddRef()</code> on the <code>IUnknown</code> looks like this</p>
  
  <pre><code>xor eax, eax
  retn 0x0C
  </code></pre>
  
  <p>Thats all, so every call into <code>AddRef()</code> corrupts the stack.  Its interesting because sometimes it would work, and other times not but it turns out it had more to do with the stack i.e. Stack allocated variables.  </p>
  
  <p>I have no idea how to work this now.  I am trying to avoid a native wrapper because of portability issues, but I dont think there is any way get around this with managed code alone.  </p>
  
  <p>On another note what the heck was Microsoft thinking.  Doesn't this violate there own rules of COM.  I am having a hard time understanding how they could release code that corrupts the stack like that.  </p>