title: AccessViolationException at no specific code-location while debugging
body: <p>I get an <code>AccessViolationException</code> while debugging an application, but don't get this exception while running this application as release without attached debugger. The application is a very thread-intensive (up to 10000+) network-server (tcp/socket).</p>
  
  <p>The application has run the whole last night compiled as release, without attached debugger and under heavy load. In fact the application didn't ever crash without attached debugger.</p>
  
  <p>When I run the application compiled as <code>Release</code> with attached debugger I get an <code>AccessViolationException</code>-Exception (sometimes). This exception just gets thrown without any hint where this exception occurs. When I press Ok in the appearing exception-box in Visual Studio and then navigate to the thread where the exception occurred. I can't see any code or stacktrace there:</p>
  
  <p><img src="https://i.stack.imgur.com/5ELbW.png" alt="Thread with exception has no memory-location.">
  <em>(Thread #186840 has no memory-location.)</em></p>
  
  <p>This is my (reduced) test-program: <a href="http://kwick.ghost-home.de/dist/q2.zip" rel="nofollow noreferrer">example-code</a>. (You should have enough ram and cpu and you should compile it as release. First start the server-application, then generate load with the client-application.)</p>
  
  <p>Now my question(s): <strong>How can I debug such errors? Does anyone know about a bug in .NET while debugging such thread-intensive programs?</strong></p>
  
  <p>I'm using Visual Studio 2013 Update 4. The project is a <code>Any Cpu</code>; <code>.NET 4.0</code> <code>C#</code> project. I have installed all windows update patches and was running this on Windows 8.1. The JIT compiler compiled the code to x64.</p>