title: .NET 4.5: internal error in the .NET Runtime (80131506) / disabling concurrent GC
body: <p>I have a long-running .NET 4.5 application that crashes randomly, leaving the message I've mentioned in the question title in the event log. The issue is reproduced on 3 different machines and 2 different systems (2008 R2 and 2012). Application doesn't use any unsafe/unmanaged components, it's pure managed .NET, with the only unmanaged thing being the CLR itself.</p>
  
  <p>Here's the stack trace of the crash site that I've extracted from the dump:</p>
  
  <pre><code>clr.dll!MethodTable::GetCanonicalMethodTable()  
  clr.dll!SVR::CFinalize::ScanForFinalization()  - 0x1a31b bytes  
  clr.dll!SVR::gc_heap::mark_phase()  + 0x328 bytes   
  clr.dll!SVR::gc_heap::gc1()  + 0x95 bytes   
  clr.dll!SVR::gc_heap::garbage_collect()  + 0x16e bytes  
  clr.dll!SVR::gc_heap::gc_thread_function()  + 0x3e bytes    
  clr.dll!SVR::gc_heap::gc_thread_stub()  + 0x77 bytes    
  kernel32.dll!BaseThreadInitThunk()  + 0x1a bytes    
  ntdll.dll!RtlUserThreadStart()  + 0x21 bytes    
  </code></pre>
  
  <p>This issue closely resembles the one that was discussed <a href="https://stackoverflow.com/questions/4367664/application-crashes-with-internal-error-in-the-net-runtime">here</a>, so I tried the solutions suggested in that topic, but none of them helped:</p>
  
  <ul>
  <li><p>I've tried installing <a href="http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=2640103&amp;kbln=en-us" rel="nofollow noreferrer">this</a> hotfix, but it won't install on any of my machines (KB2640103 does not apply, or is blocked by another condition on your computer), which actually makes sense, because I'm using 4.5, not 4.0.</p></li>
  <li><p>I've tried disabling concurrent GC and/or enabling server GC. Right now the relevant part of my app.config looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;        
      &lt;runtime&gt;
          &lt;gcConcurrent enabled="false"/&gt;
          &lt;gcServer enabled="true" /&gt;
      &lt;/runtime&gt;
  &lt;startup&gt;&lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/&gt;    &lt;/startup&gt;&lt;/configuration&gt;
  </code></pre></li>
  </ul>
  
  <p>Though the weird thing is I still find multiple GC-related threads in the process dump. Besides the one the crash occurs in, there are 7 threads with the following stack trace:</p>
  
  <pre><code>ntdll.dll!NtWaitForSingleObject()  + 0xa bytes  
  KERNELBASE.dll!WaitForSingleObjectEx()  + 0x9a bytes    
  clr.dll!CLREventBase::WaitEx()  + 0x13f bytes   
  clr.dll!CLREventBase::WaitEx()  + 0xf7 bytes    
  clr.dll!CLREventBase::WaitEx()  + 0x78 bytes    
  clr.dll!SVR::t_join::join()  + 0xd8 bytes   
  clr.dll!SVR::gc_heap::scan_dependent_handles()  + 0x65 bytes    
  clr.dll!SVR::gc_heap::mark_phase()  + 0x347 bytes   
  clr.dll!SVR::gc_heap::gc1()  + 0x95 bytes   
  clr.dll!SVR::gc_heap::garbage_collect()  + 0x16e bytes  
  clr.dll!SVR::gc_heap::gc_thread_function()  + 0x3e bytes    
  clr.dll!SVR::gc_heap::gc_thread_stub()  + 0x77 bytes    
  kernel32.dll!BaseThreadInitThunk()  + 0x1a bytes    
  ntdll.dll!RtlUserThreadStart()  + 0x21 bytes    
  </code></pre>
  
  <p>Which makes me wondering if I could somehow screw up disabling the concurrent GC (that's what I actually listed the config for).</p>
  
  <p>I think that wraps up what I've managed to find so far. I could really use some help on how to proceed with dealing with this issue.</p>