title: Explain critical bug in Visual Studio 2010 and up, WinForms and WPF
body: <p>Try putting the following code inside <code>Load</code> event handler for WinForms or <code>Loaded</code> for WPF.</p>
  
  <pre><code>Dim doc As New XmlDocument
  Dim nsmgr As New XmlNamespaceManager(Nothing) 'this line throws an exception
  </code></pre>
  
  <p>Problem is that exception is not thrown, and stack corruption happens. It may have different side effects, depending on the IDE - see below.</p>
  
  <ul>
  <li>Affected IDEs are: 2008, 2010 and 2012 (those I could test). 2010 resets stack state, and returns from sub/handler, like nothing happened (but without proceeding with other statements there). 2012 may warn a user about a failed application and an attempt to run in <code>compatibility mode</code>. Next time after that it runs the same as 2010. 2008 properly throws an exception, but only on default configuration (AnyCPU). Switching platform target to x86 makes the problem reappear in 2008 as well.</li>
  <li>Affected frameworks are WinForms and WPF. Console apps and ASP.NET
  seem to work fine. .NET v2.0-4.5.</li>
  <li>Affected scope is only <code>Load</code> event so far.
  Putting this code into a button makes it work.</li>
  <li>Affected build
  configuration = any. Tried on default <code>Debug</code> and <code>Release</code>.</li>
  </ul>
  
  <p>Why I consider it a bug is because it can leave objects in an unstable state - they did not finish initializing, which is not an expected behavior. What's critical about it is that nobody will know it happened, as it does not throw an exception. Depending on your design, you may end up with incorrect data in your database, which in the worst case may lead to severe consequences.</p>
  
  <p>Does anyone have a good explanation to why this may be happening and if there is a workaround?</p>