title: What's the cause of this FatalExecutionEngineError in .NET 4.5 beta?
body: <p>The sample code below occurred naturally. Suddenly my code thew a very nasty-sounding <code>FatalExecutionEngineError</code> exception. I spent a good 30 minutes trying to isolate and minimize the culprit sample. Compile this using Visual Studio 2012 as a console app:</p>
  
  <pre><code>class A&lt;T&gt;
  {
      static A() { }
  
      public A() { string.Format("{0}", string.Empty); }
  }
  
  class B
  {
      static void Main() { new A&lt;object&gt;(); }
  }
  </code></pre>
  
  <p>Should produce this error on .NET framework 4 and 4.5:</p>
  
  <p><img src="https://i.stack.imgur.com/8NxRZ.gif" alt="FatalExecutionException screenshot"></p>
  
  <p>Is this a known bug, what is the cause and what can I do to mitigate it? My current work around is to not use <code>string.Empty</code>, but am I barking up the wrong tree? Changing anything about that code makes it function as you would expect - for example removing the empty static constructor of <code>A</code>, or changing the type paramter from <code>object</code> to <code>int</code>.</p>
  
  <p>I tried this code on my laptop and it didn't complain. However, I did try my main app and it crashed on the laptop as well. I must have mangled away something when reducing the problem, I'll see if I can figure out what that was.</p>
  
  <p>My laptop crashed with the same code as above, with framework 4.0, but main crashes even with 4.5. Both systems are using VS'12 with latest updates (July?).</p>
  
  <p><strong>More information</strong>:</p>
  
  <ul>
  <li>IL Code (compiled Debug/Any CPU/4.0/VS2010 (not that IDE should matter?)): <a href="http://codepad.org/boZDd98E" rel="nofollow noreferrer">http://codepad.org/boZDd98E</a></li>
  <li>Not seen VS 2010 with 4.0. Not crashing with/without optimizations, different target CPU, debugger attached/not attached, etc. - <a href="https://stackoverflow.com/users/453277/tim-medora">Tim Medora</a></li>
  <li>Crashes in 2010 if I use AnyCPU, is fine in x86. Crashes in Visual Studio 2010 SP1, using Platform Target = AnyCPU, but fine with Platform Target=x86. This machine has VS2012RC installed as well so 4.5 possibly doing an in-place replacement.  Use AnyCPU and TargetPlatform = 3.5 then it doesn't crash so looks like a regression in the Framework.- <a href="https://stackoverflow.com/users/473194/colinsmith">colinsmith</a></li>
  <li>Cannot reproduce on x86, x64 or AnyCPU in VS2010 with 4.0. – <a href="https://stackoverflow.com/users/408182/fuji">Fuji</a></li>
  <li>Only happens for x64, (2012rc, Fx4.5) - <a href="https://stackoverflow.com/users/60761/henk-holterman">Henk Holterman</a></li>
  <li>VS2012 RC on Win8 RP. Initially Not seeing this MDA when targeting .NET 4.5. When switched to targeting .NET 4.0 the MDA appeared. Then after switching back to .NET 4.5 the MDA remains. - <a href="https://stackoverflow.com/users/18482/wayne">Wayne</a></li>
  </ul>