Access violation in Entity Framework code accessing SQL Server
We've encountered an access violation on our test machine, in Entity Framework code. I'm wondering if this coul开发者_Go百科d potentially be due to a threading bug, or if it's more likely due to hardware issues.
Here is a partial call stack:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Data.Common.Internal.Materialization.CoordinatorFactory`1..ctor(Int32 depth, Int32 stateSlot, Expression hasData, Expression setKeys, Expression checkKeys, CoordinatorFactory[] nestedCoordinators, Expression element, Expression elementWithErrorHandling, Expression initializeCollection, RecordStateFactory[] recordStateFactories)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct& signature, RuntimeType declaringType)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at System.Data.Common.Internal.Materialization.CoordinatorScratchpad.Compile()
This happened in our ASP.NET app on IIS 7 (Server 2008 R2 SP1), using Entity Framework 4 to access SQL Server 2008 R2. I've read about access violations with EF and SQL Server CE, but we are using the full SQL Server. We aren't directly interacting with any native code from our app - no P/Invoke or COM interop.
This has only happened once. Personally I think it's a problem with the machine, not the application... the machine has BSOD'd a couple times before. But I was asked to look into it as a possible bug.
I'll look into setting up DebugDiag to catch this if it happens again. Does anyone have any other suggestions?
Thanks, RichardI think you're probably right, I would guess that there was some other code running in the same worker process which caused some memory corruption that resulted in this error.
If there are other applications running in this worker process, you might want to look at separating this application out into a dedicated worker. Other than that I would put it into the "lets just keep an eye out" category.
Upgrading to .NET 4.5.2 fixed a similar problem for us that was occurring on a virtual function call in EF6 and elsewhere.
https://entityframework.codeplex.com/workitem/2430
https://connect.microsoft.com/VisualStudio/feedback/details/825555/accessviolationexception-in-sqlconnection
https://ucuuba.wordpress.com/2014/08/25/ef-system-accessviolationexception/
精彩评论