Exception: Collection was modified; enumeration operation may not execute...

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
vlad.tryhub
Posts: 3
Joined: Thu 12 Jul 2018 16:35

Exception: Collection was modified; enumeration operation may not execute...

Post by vlad.tryhub » Thu 12 Jul 2018 17:01

Hi. We are experiencing problems with MySQL provider for EF Core. It seems to be some issues with concurrency. We are using dotconnect for MySQL in ASP.NET Core application. Sometimes query execution throws an exception and results in a failed web request.
Also, we have made a simple console application which reproduces described errors by emulating load of our API application. The link: https://github.com/Dyavolik/devart-bug. Along with demo console application, you will find DB dump there.
This problem does a huge impact on our development process, so we ask for any information about the status of the problem.

Exception logs:

1:

Code: Select all

System.AggregateException: One or more errors occurred. (Collection was modified; enumeration operation may not execute.) ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at ??.(IList`1 )
   at ??.????(? )
   at ??.VisitBinary(BinaryExpression )
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at ??.VisitBinary(BinaryExpression )
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at ??.????(SelectExpression )
   at ??.????(SelectExpression )
   at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](T node, String callerName)
   at ??.CreateDefault(SelectExpression )
   at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.<NotifyReaderCreated>b__14_0(FactoryAndReader s)
   at Microsoft.EntityFrameworkCore.Internal.NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue& target, TParam param, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.NotifyReaderCreated(DbDataReader dataReader)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.BufferlessMoveNext(DbContext _, Boolean buffer, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator`2.MoveNextCore(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.AsyncIterator`1.MoveNext(CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable`1 source, TAccumulate seed, Func`3 accumulator, Func`2 resultSelector, CancellationToken cancellationToken)
   at BugReplication.Program.<>c.<<Main>b__1_1>d.MoveNext() in C:\Users\Vlad\source\repos\s\davart-bug\DevartBug\Program.cs:line 23
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.WaitAllCore(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
   at BugReplication.Program.Main(String[] args) in C:\Users\Vlad\source\repos\s\davart-bug\DevartBug\Program.cs:line 28
---> (Inner Exception #0) System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at ??.(IList`1 )
   at ??.????(? )
   at ??.VisitBinary(BinaryExpression )
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at ??.VisitBinary(BinaryExpression )
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at ??.????(SelectExpression )
   at ??.????(SelectExpression )
   at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](T node, String callerName)
   at ??.CreateDefault(SelectExpression )
   at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.<NotifyReaderCreated>b__14_0(FactoryAndReader s)
   at Microsoft.EntityFrameworkCore.Internal.NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue& target, TParam param, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.NotifyReaderCreated(DbDataReader dataReader)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.BufferlessMoveNext(DbContext _, Boolean buffer, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator`2.MoveNextCore(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.AsyncIterator`1.MoveNext(CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable`1 source, TAccumulate seed, Func`3 accumulator, Func`2 resultSelector, CancellationToken cancellationToken)
   at BugReplication.Program.<>c.<<Main>b__1_1>d.MoveNext() in C:\Users\Vlad\source\repos\s\davart-bug\DevartBug\Program.cs:line 23<---
2:

Code: Select all

System.AggregateException: One or more errors occurred. (Collection was modified; enumeration operation may not execute.) (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3) (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3) (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3) (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3) (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3) (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3) (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3) (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3) (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3) (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3) (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3) ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at ??.(IList`1 )
   at ??.????(? )
   at ??.VisitBinary(BinaryExpression )
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at ??.VisitBinary(BinaryExpression )
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at ??.????(SelectExpression )
   at ??.????(SelectExpression )
   at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](T node, String callerName)
   at ??.CreateDefault(SelectExpression )
   at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.GetRelationalCommand(IReadOnlyDictionary`2 parameters)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.BufferlessMoveNext(DbContext _, Boolean buffer, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator`2.MoveNextCore(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.AsyncIterator`1.MoveNext(CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable`1 source, TAccumulate seed, Func`3 accumulator, Func`2 resultSelector, CancellationToken cancellationToken)
   at BugReplication.Program.<>c.<<Main>b__1_1>d.MoveNext() in C:\Users\Vlad\source\repos\s\davart-bug\DevartBug\Program.cs:line 23
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.WaitAllCore(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
   at BugReplication.Program.Main(String[] args) in C:\Users\Vlad\source\repos\s\davart-bug\DevartBug\Program.cs:line 28
---> (Inner Exception #0) System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at ??.(IList`1 )
   at ??.????(? )
   at ??.VisitBinary(BinaryExpression )
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at ??.VisitBinary(BinaryExpression )
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at ??.????(SelectExpression )
   at ??.????(SelectExpression )
   at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](T node, String callerName)
   at ??.CreateDefault(SelectExpression )
   at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.GetRelationalCommand(IReadOnlyDictionary`2 parameters)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.BufferlessMoveNext(DbContext _, Boolean buffer, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator`2.MoveNextCore(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.AsyncIterator`1.MoveNext(CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable`1 source, TAccumulate seed, Func`3 accumulator, Func`2 resultSelector, CancellationToken cancellationToken)
   at BugReplication.Program.<>c.<<Main>b__1_1>d.MoveNext() in C:\Users\Vlad\source\repos\s\davart-bug\DevartBug\Program.cs:line 23<---

---> (Inner Exception #1) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3<---

---> (Inner Exception #2) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3<---

---> (Inner Exception #3) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3<---

---> (Inner Exception #4) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3<---

---> (Inner Exception #5) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3<---

---> (Inner Exception #6) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3<---

---> (Inner Exception #7) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3<---

---> (Inner Exception #8) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3<---

---> (Inner Exception #9) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3<---

---> (Inner Exception #10) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3<---

---> (Inner Exception #11) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ) = '2018-06-25 00:00:00')' at line 3<---

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Exception: Collection was modified; enumeration operation may not execute...

Post by Shalex » Mon 16 Jul 2018 15:44

The issue is fixed. You can download the internal build with the fix from https://www.devart.com/pub/nuget_mysql_8_11_1186.zip.

Toshik
Posts: 5
Joined: Thu 19 Jul 2018 15:48

Re: Exception: Collection was modified; enumeration operation may not execute...

Post by Toshik » Thu 19 Jul 2018 15:51

Still getting "Collection was modified; enumeration operation may not execute." sometimes under high load:

"Devart.Data.MySql.EFCore" Version "8.12.1190"

Code: Select all

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.VisitChildren(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node)
   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
   at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.Expressions.ColumnExpression.VisitChildren(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node)
   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
   at Microsoft.EntityFrameworkCore.Query.Expressions.ColumnExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.Sql.DefaultQuerySqlGenerator.ApplyOptimizations(Expression expression, Boolean searchCondition, Boolean joinCondition)
   at Microsoft.EntityFrameworkCore.Query.Sql.DefaultQuerySqlGenerator.GenerateProjection(Expression projection)
   at Microsoft.EntityFrameworkCore.Query.Sql.DefaultQuerySqlGenerator.GenerateList[T](IReadOnlyList`1 items, Action`1 generationAction, Action`1 joinAction)
   at Microsoft.EntityFrameworkCore.Query.Sql.DefaultQuerySqlGenerator.VisitSelect(SelectExpression selectExpression)
   at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Remotion.Linq.Parsing.ThrowingExpressionVisitor.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Sql.DefaultQuerySqlGenerator.GenerateSql(IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.GetRelationalCommand(IReadOnlyDictionary`2 parameters)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.BufferlessMoveNext(DbContext _, Boolean buffer, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator`2.MoveNextCore(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.AsyncIterator`1.MoveNext(CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable`1 source, TAccumulate seed, Func`3 accumulator, Func`2 resultSelector, CancellationToken cancellationToken)

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Exception: Collection was modified; enumeration operation may not execute...

Post by Shalex » Fri 20 Jul 2018 08:42

@vlad.tryhub
The bug with translating calls to properties and methods in LINQ query to SQL statement in EF Core 2.1 is fixed in a public build: viewtopic.php?f=2&t=37477 .

@Toshik
Your stack trace is different. Could you please upload a simple test project with the corresponding DDL/DML script to ftp://ftp.devart.com (credentials: anonymous / yourEmail)?

Post Reply