Access violation in Entity Framework code accessing SQL Server

允我心安 提交于 2019-12-20 06:28:12

问题


We've encountered an access violation on our test machine, in Entity Framework code. I'm wondering if this could 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,
Richard


回答1:


I 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.




回答2:


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/



来源:https://stackoverflow.com/questions/6820677/access-violation-in-entity-framework-code-accessing-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!