title: "LoaderLock was detected" with Visual Studio 2012
body: <p>I have a couple of MVC projects which use SQL CE 4.0 and Entity Framework. Since moving to Visual Studio 2012 I keep getting the following error (not every time, but frequently)</p>
  
  <p>LoaderLock was detected</p>
  
  <p>Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.</p>
  
  <p>The error does not occur if I go back to using VS 2010, which makes me fairly certain it is an issue with Visual Studio rather than my code, but I would like someone to confirm that for me!</p>
  
  <p><strong>Edit</strong></p>
  
  <p>The problem always seems to occur when the Dispose() method of the dbcontext is called. Here is a screenshot of the Exception Assistant:</p>
  
  <p><img src="https://i.stack.imgur.com/QBhNv.png" alt="Exception Assistant"></p>