我们在测试机器上的实体框架代码中遇到了访问冲突。我想知道这是否可能是由于线程错误造成的,或者更可能是由于硬件问题造成的。
下面是部分调用堆栈:
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()
这发生在 IIS 7 (Server 2008 R2 SP1) 上的 ASP.NET 应用程序中,使用 Entity Framework 4 访问 SQL Server 2008 R2。我读过EF 和 SQL Server 的访问冲突CE,但我们使用的是完整的 SQL Server。我们不直接与应用程序中的任何本机代码交互 - 没有 P/Invoke 或 COM 互操作。
这种事只发生过一次。就我个人而言,我认为这是机器的问题,而不是应用程序的问题......机器之前已经出现过几次蓝屏死机。但我被要求将其视为可能的错误进行调查。
如果再次发生这种情况,我将考虑设置 DebugDiag 来捕获此情况。有人还有其他建议吗?
谢谢,
理查德
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
发布评论
评论(2)
我认为您可能是对的,我猜测在同一个工作进程中运行了一些其他代码,导致了一些内存损坏,从而导致了此错误。
如果此工作进程中正在运行其他应用程序,您可能需要考虑将此应用程序分离到专用工作进程中。除此之外,我会将其归入“让我们留意”类别。
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.
升级到 .NET 4.5.2 解决了 EF6 和其他地方的虚拟函数调用中发生的类似问题。
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/
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/