Note that there are some explanatory texts on larger screens.

plurals
  1. POBuildNotContainsExpression causes System.StackOverflowException with large data set on Windows 7 -64-bit
    primarykey
    data
    text
    <p>I have encountered a condition where my app crashes with a particular dataset on Windows 7, 64-bit. All other platforms work fine on the same dataset. I have determined that my app is crashing in the BuildNotContainsExpression that many people have posted.</p> <p>Is there a way for the expression to be built using memory from the heap?<br> Should I just break done my usersActive list and process smaller chunks at a time (like 1000)?<br> Something else? </p> <pre><code>List&lt;int&gt; usersActive = myContext.myTable.Select(a =&gt; a.tableUsersSnapshot.id).Distinct().ToList(); // The code blows up (only on Win7 64-bit) on this line when usersActive is large ~4000 // (probably will blow up on all platforms if usersActive is sufficiently large) expTest = CustomExpressions.BuildNotContainsExpression&lt;tableUsersSnapshot, int&gt;(a =&gt; a.id, usersActive); List&lt;tableUsersSnapshot&gt; usersToDelete = myContext.myTableSnapshot.Where(expTest).ToList(); // Delete the objects in the delete list foreach(tableUsersSnapshot user in usersToDelete) { myContext.DeleteObject(user); } </code></pre> <p>Edit: Here's the BuildNotContains function - it is not recursive: </p> <pre><code>public static Expression&lt;Func&lt;TElement, bool&gt;&gt; BuildNotContainsExpression&lt;TElement, TValue&gt;(Expression&lt;Func&lt;TElement, TValue&gt;&gt; valueSelector, IEnumerable&lt;TValue&gt; values) { if (null == valueSelector) { throw new ArgumentNullException("valueSelector");} if (null == values) { throw new ArgumentNullException("values"); } ParameterExpression p = valueSelector.Parameters.Single(); // p =&gt; valueSelector(p) != values[0] &amp;&amp; valueSelector(p) != ... if (!values.Any()) { return e =&gt; true; } var equals = values.Select(value =&gt; (Expression)Expression.NotEqual(valueSelector.Body, Expression.Constant(value, typeof(TValue)))); var body = equals.Aggregate&lt;Expression&gt;((accumulate, equal) =&gt; Expression.And(accumulate, equal)); return Expression.Lambda&lt;Func&lt;TElement, bool&gt;&gt;(body, p); } </code></pre> <p>Here's the applicable portion of my EDMX diagram: <img src="https://i.stack.imgur.com/3T8c6.png" alt="alt text"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload