title: .Net 2.0: Help troubleshooting a System.AccessViolationException. 100% managed code
body: <p>This is kind of repeated from <a href="https://stackoverflow.com/questions/1444844/can-a-system-accessviolationexception-happen-because-of-faulty-ram">my previous question</a>, although the objective of my question is completely different now.</p>
  
  <p>I'm getting, now and then, about once a week, only in my development machine, a System.AccessViolationException in a web app I made.</p>
  
  <p>Since my machine is having a few things that don't work quite well (like a blue screen every now and then), I assumed before it might be faulty RAM. After 24 hours running memtest, i'm pretty sure it's not...</p>
  
  <p>So, this is the situation: This is a wep App, VB.Net 2.0, 100% managed code, doesn't use COM, Interop, or anything like that. It's running on a Windows Server 2008 SP2 box.<br>
  The only "strange" thing I'm doing is starting 3 threads of my own when the app starts, that do "cron like" stuff inside the appdomain, and also most of the requests this app is handling are handled asynchronously, and many of them are held open without a response for up to 30 seconds. (I'm doing Comet long-polling).</p>
  
  <p>Also, i've been working on this code for about a year now, and it's only started to do this about a month ago.
  I can't think of anything major or important that I changed on this whole web app that I changed lately. I've been working almost fully on the Javascript frontend.</p>
  
  <hr>
  
  <p>When the exception happens, I get the typical popup asking me whether I want to debug.
  When I do, I see all the ASP.Net threads plus my 3 threads.<br>
  My 3 threads are in a call to Sleep(), which is normal. All the other ASP.Net threads have no call stack at all.<br>
  In the thread where Visual Studio tells me I got the exception, I don't see anything.</p>
  
  <p>So I don't know for sure where the error happens, or even whether it happens every time in the same place or not.</p>
  
  <p>All I could find as a clue is this in the "Application" event log:</p>
  
  <pre><code>Faulting application w3wp.exe, version 7.0.6002.18005, time stamp 0x49e03238, 
  faulting module unknown, version 0.0.0.0, time stamp 0x00000000, exception code 
  0xc0000005, fault offset 0x0000000002358fe8, process id 0x1f4c, application 
  start time 0x01ca41395c564ed9.
  </code></pre>
  
  <p>And right after that, another event with this: </p>
  
  <pre><code>An unhandled exception occurred and the process was terminated.
  
  Application ID: DefaultDomain    
  Process ID: 6632    
  Exception: System.AccessViolationException
  
  Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  
  StackTrace:    at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus&amp; notificationStatus)
     at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
     at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
  </code></pre>
  
  <hr>
  
  <p>I've googled MgdIndicateCompletion , but couldn't find anything really useful...</p>
  
  <p>One thing that HAS changed about a month ago, now that I think of it, is that I moved from Server 2003 x86 to Server 2008 x64 (and thus, IIS6 to IIS7) in my dev machine. Maybe that's the cause, but still, i'm not sure what to make of this...</p>
  
  <p>I mean, this would place the problem completely out of my codebase, right?</p>
  
  <hr>
  
  <p><strong>UPDATE:</strong> As suggested <a href="http://forums.asp.net/t/1476904.aspx" rel="nofollow noreferrer">here</a>, turning the App Pool integration to "Classic" seems to fix it. I'm still looking for a decent solution, or at least an explanation, though.</p>