[Investigate EF6] Stack overflow exception in EntityFramework.dll


I am getting the error 'An unhandled exception of type 'System.StackOverflowException' occurred in EntityFramework.dll' when trying to execute a fairly large expression.

I have tested the expression with entity framework 5 and it works as expected, however when upgrading to entityframework 6 beta 1 the exception is thrown.

I have attached a copy of the call stack, it appears to be throwing the exception when calling System.Data.Entity.Core.Query.PlanCompiler.NestPullup.

file attachments

Closed Sep 3, 2013 at 7:26 PM by RoMiller
To avoid confusion by repurposing this issue we have created a new issue to track reducing stack size when UseDatabaseNullSemantics is set to false - https://entityframework.codeplex.com/workitem/1621.


maumar wrote Aug 24, 2013 at 12:41 AM

Could you try this query against the latest nightly build?
Here are the instructions:

There has been one change in particular, that might have affected the number of Applies we generate, and this change has been reverted in the current codebase. My suspicion is that thing should work with the current build.

SamuelWhitby wrote Aug 25, 2013 at 11:56 PM

Hi Maumar, I have tried the query with the latest build and I am still getting the exception. I have attached a copy of the query if that will help.

divega wrote Aug 26, 2013 at 8:42 PM

Looking at the attached copy this looks there could be unintended recursion in some of the changes we made in EF6. I am assigned this to Emil since he is familiar with the changes we made.

emilcicos wrote Aug 26, 2013 at 11:44 PM

Is it possible to also get a sample model so we can try to repro this and investigate?

emilcicos wrote Aug 27, 2013 at 9:01 PM

It seems this is caused by the null comparison semantics. In EF5 the default was the use of database semantics, in EF6 the default is C# semantics.

To get the default EF5 behavior the null comparison semantics can be set using:

dbContext.Configuration.UseDatabaseNullSematics = true; // EF6 default is false

or the legacy version:

((IObjectContextAdapter)dbContext).ObjectContext.ContextOptions.UseCSharpNullComparisonBehavior = false; // EF6 default is true

We have to investigate why the expression tree and the query generated is significantly larger in the case of C# null comparison semantics, but in terms of parity with EF5 this does not seem to be a regression.

emilcicos wrote Aug 27, 2013 at 9:19 PM

Please confirm if the workaround above can be used to resolve this issue.

SamuelWhitby wrote Aug 29, 2013 at 1:09 AM

Thanks emilcicos,
Adding dbContext.Configuration.UseDatabaseNullSematics = true; has solved the problem and is a suitable work around for now.

On another note I am also getting the exception 'Index was outside the bounds of the array' thrown with a similar query, perhaps you could investigate that too. I have listed it here https://entityframework.codeplex.com/workitem/1603.