LinQ Attempt to read or write protected memory. This is often an indication that the other memory is corrupt


I am getting the memory access violation error:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Thread information: Thread ID: 5 Thread account name: IIS APPPOOL\OpenSpanServerAppPool Is impersonating: False Stack trace: at System.Linq.Enumerable.WhereEnumerableIterator1.Select[TResult](Func2 selector) at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable1 source, Func2 selector) at System.Web.Mvc.MvcHandler.RemoveOptionalRoutingParameters() at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I am using MVC, NHibernate and my site is hosted in IIS with its own pool , DB is SQL Server 2005 sp3.

Did you see something related to this issue?

I think it is related maybe to MS SQL idle disconnection...

Any idea?

I would appreciate your help.

We've hit the same issue from time-to-time. I think Sam hit the answer, our problem appears to be because we late evaluating our database read and the connection had timed out. The problem appears to have been resolved by putting a ToList call in our data layer to make sure the conversion happens earlier.