title: Finding the cause of System.AccessViolationException
body: <p>Our application experiences the odd fatal System.AccessViolationException.  We see these as we've configured the AppDomain.CurrentDomain.UnhandledException event to log the exception.</p>
  
  <pre><code>Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
     at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
     at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
     at System.Windows.Forms.Application.Run(Form mainForm)
     at Bootstrap.Run() in e:\build-dir\src\Bootstrap.cs:line 25
  </code></pre>
  
  <p>The exception itself doesn't seem to contain any more information than the message <em>"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."</em></p>
  
  <ul>
  <li>What steps can we now take to get to the cause of the problem?  </li>
  <li>Is there any way to determine the illegal address or pointer value that caused the crash?  </li>
  <li>Can we find out what native library code was causing the problem?</li>
  <li>Is there more debugging/tracing we can enable?</li>
  </ul>
  
  <p><strong>UPDATE</strong></p>
  
  <ul>
  <li>Could this be caused by earlier non-threadsafe use of the WinForms API?</li>
  </ul>