title: Free-running application under test exits shortly after I attach with VS2010 SP1 in x86
body: <p>On Windows 7 x64, when I attach in x86 mode to a fairly complex free-running app, it runs for a while, then reproducibly exits.</p>
  
  <pre><code>MyApp.exe Managed (v4.0.30319)' has exited with code -1073740791 (0xc0000409).
  </code></pre>
  
  <p>followed immediately by</p>
  
  <pre><code>MyApp.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
  </code></pre>
  
  <p>Sometimes if it runs OK, it would hit my breakpoint, I'll inspect the state, but when I hit F5 to keep going, the app exits in the same fashion.</p>
  
  <p>Quick search for the error code tells me that it's a Stack Buffer Overrun.  I hear that it might be caused by incorrect unmanaged interop code.</p>
  
  <p>I can run from debugger OK (F5), but free-running and attaching always has this problem.</p>
  
  <p>Any thoughts on how I could narrow it down?</p>
  
  <p>EDIT:  Here's a callstack i am seeing on a different machine (Windows Server 2008 R2 x64) here, might be related:</p>
  
  <blockquote>
    <p>clr.dll!__crt_debugger_hook()<br>
        clr.dll!___report_gsfailure()  + 0xeb bytes 
        clr.dll!_DoJITFailFast@0()  + 0x8 bytes 
        clr.dll!CrawlFrame::SetCurGSCookie()  + 0x2e9c4f bytes<br>
        clr.dll!StackFrameIterator::Init()  + 0x60 bytes<br>
        clr.dll!Thread::StackWalkFramesEx()  + 0x8a bytes<br>
        clr.dll!Thread::StackWalkFrames()  + 0x87 bytes 
        clr.dll!CNameSpace::GcScanRoots()  + 0xd7 bytes 
        clr.dll!WKS::gc_heap::mark_phase()  + 0xae bytes<br>
        clr.dll!WKS::gc_heap::gc1()  + 0x7b bytes<br>
        clr.dll!WKS::gc_heap::garbage_collect()  + 0x1c1 bytes<br>
        clr.dll!WKS::GCHeap::GarbageCollectGeneration()  + 0xba bytes<br>
        clr.dll!WKS::gc_heap::try_allocate_more_space()  + 0x1cd0 bytes 
        clr.dll!WKS::gc_heap::allocate_more_space()  + 0x13 bytes<br>
        clr.dll!WKS::GCHeap::Alloc()  + 0x507 bytes 
        clr.dll!Alloc()  + 0x5a bytes<br>
        clr.dll!SlowAllocateString()  + 0x41 bytes<br>
        clr.dll!UnframedAllocateString()  + 0x11 bytes<br>
        clr.dll!StringObject::NewString()  + 0x26 bytes 
        clr.dll!Int64ToDecStr()  + 0x12e bytes<br>
        clr.dll!COMNumber::FormatInt64()  + 0x17e bytes 
        mscorlib.ni.dll!6c60b8e1()<br>
        [Frames below may be incorrect and/or missing, no symbols loaded for mscorlib.ni.dll]   </p>
  </blockquote>
  
  <p><strong>EDIT2</strong>  Things seem fine on x64 build of the app, issue only appears in x86.</p>