Collection was modified; enumeration operation may not execute

Collection was modified; enumeration operation may not execute

Postby ricsmania » Wed 29 Jun 2016 16:11

Hello,

I'm getting this error when trying to read records concurrently and using Include to get the children:

Collection was modified; enumeration operation may not execute

The line that throws the error is this:

Code: Select all
return Ok(_context.Blogs.Include(blog => blog.Posts).FirstOrDefault(blog => blog.Id == id));


There doesn't seem to be anything wrong with the code, so it might be a bug.

dotConnect version 9.1.45.

Full explanation and code samples here: http://stackoverflow.com/questions/38101571/dotconnect-with-entityframework-core-returns-collection-was-modified-enumeratio

Thanks.
ricsmania
 
Posts: 9
Joined: Fri 17 Jun 2016 16:37

Re: Collection was modified; enumeration operation may not execute

Postby Shalex » Thu 07 Jul 2016 16:02

Entity Framework Core 1.0 RTM is supported in the newest (9.1.55) build of dotConnect for Oracle: https://www.devart.com/dotconnect/oracle/revision_history.html. Please try it and upgrade your project to Core 1.0 RTM. Does this help?
Shalex
Devart Team
 
Posts: 7705
Joined: Thu 14 Aug 2008 12:44

Re: Collection was modified; enumeration operation may not execute

Postby ricsmania » Wed 13 Jul 2016 11:12

Hello Shalex,

I tried the 9.1.55 version with EF 1.0 but got the same error.

It is pretty easy to reproduce:

Create a Nuget from DotConnect 9.1.55 with the name Devart.Data.Oracle and version 9.1.55 and add the source to VS
Clone https://github.com/ricsmania/BlogsOracleEntityFramework
Run the script src/BlogOracle/Database/Blogs.sql
Change the BlogOracle model with the correct connect string
Run BlogOracle
Run SendRequests
ricsmania
 
Posts: 9
Joined: Fri 17 Jun 2016 16:37

Re: Collection was modified; enumeration operation may not execute

Postby Shalex » Fri 15 Jul 2016 17:35

Thank you for your report. We will investigate the issue and notify you about the result.
Shalex
Devart Team
 
Posts: 7705
Joined: Thu 14 Aug 2008 12:44

Re: Collection was modified; enumeration operation may not execute

Postby Shalex » Fri 09 Sep 2016 17:13

Your project is configured to use .NET Core SDK version 1.0.0-preview1-002702. Please upgrade it to the release version and try the newest (9.1.97) build of dotConnect for Oracle.
Shalex
Devart Team
 
Posts: 7705
Joined: Thu 14 Aug 2008 12:44

Re: Collection was modified; enumeration operation may not execute

Postby Butzei » Mon 14 Aug 2017 07:21

Hi,

ricsmania was this bug fixed by the update Shalex mentioned?
I have a similar bug that looks like a async problem in dotConnect/EfCore but with a slighly different stacktrace.
Code: Select all
at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.Accept(ExpressionVisitor visitor)
Instead of your
at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.GetProjectionTypes()

It only occures on higher server load with multiple requests executed in parallel. So i think it would be hard to build an example project.



We are using Devart.Data.Oracle.Entity.EFCore 9.4.326.0 with Microsoft.EntityFrameworkCore 1.1.2.

This is our full stacktrace:
Code: Select all
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at System.Data.Common.CommandTrees.b.b(SelectExpression A_0)
at System.Data.Common.CommandTrees.b.a(SelectExpression A_0)
at System.Data.Common.CommandTrees.a.e(SelectExpression A_0)
    at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.Accept(ExpressionVisitor visitor)
at System.Data.Common.CommandTrees.a.Visit(Expression node)
at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](T node, String callerName)
    at Devart.Data.Oracle.Entity.ag.a(SelectExpression A_0)
at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.CreateDefaultQuerySqlGenerator()
at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.GetRelationalCommand(IReadOnlyDictionary`2 parameters)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(Boolean buffer)
at Microsoft.EntityFrameworkCore.Storage.Internal.NoopExecutionStrategy.Execute[TState,TResult](Func`2 operation, Func`2 verifySucceeded, TState state)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, Func`2 operation, TState state)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Qm.Tda.Dal.Services.ReadoutTimeDbService.Get(Guid boxId, Int32 sequenceNo, IReadOnlyCollection`1 lotNames) in C:\BuildAgent\work\4c7ef0c5657430ca\Qm.Tda.Dal\Services\ReadoutTimeDbService.cs:line 58
at Qm.Tda.Logic.Services.ReadoutTimeService.Get(Guid boxId, Int32 sequenceNo, IReadOnlyCollection`1 lotNames) in C:\BuildAgent\work\4c7ef0c5657430ca\Qm.Tda.Logic\Services\ReadoutTimeService.cs:line 29
at Qm.Tda.Logic.Services.FailureChartService.GetDataPoints(IEnumerable`1 errors, FailureChartRequestUnit unit, Int32 numberOfDevices) in C:\BuildAgent\work\4c7ef0c5657430ca\Qm.Tda.Logic\Services\FailureChartService.cs:line 0
at Qm.Tda.Logic.Services.FailureChartService.GetFailureChartSerie(Int32 numberOfDevices, DiagramFailureType failureType, IReadOnlyDictionary`2 convertSeriesTypes, LotMetaDao lotMetaDao, FailureChartRequestUnit unit) in C:\BuildAgent\work\4c7ef0c5657430ca\Qm.Tda.Logic\Services\FailureChartService.cs:line 146
at Qm.Tda.Logic.Services.FailureChartService.<>c__DisplayClass18_0.<GetFailureChartSeries>b__1(LotMetaDao lotMetaDao) in C:\BuildAgent\work\4c7ef0c5657430ca\Qm.Tda.Logic\Services\FailureChartService.cs:line 139
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Qm.Tda.Logic.Services.FailureChartService.GetFailureChartSeries(Int32 numberOfDevices, FailureChartRequestUnit unit, Dictionary`2 convertSeriesTypes) in C:\BuildAgent\work\4c7ef0c5657430ca\Qm.Tda.Logic\Services\FailureChartService.cs:line 139
at Qm.Tda.Logic.Services.FailureChartService.<GetFailureChartAsync>d__12.MoveNext() in C:\BuildAgent\work\4c7ef0c5657430ca\Qm.Tda.Logic\Services\FailureChartService.cs:line 72
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Qm.Tda.Api.Controllers.FailureChartController.<GetFailureChart>d__4.MoveNext() in C:\BuildAgent\work\4c7ef0c5657430ca\Qm.Tda.Api\Controllers\FailureChartController.cs:line 73
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
Butzei
 
Posts: 12
Joined: Fri 26 May 2017 07:41

Re: Collection was modified; enumeration operation may not execute

Postby Shalex » Tue 15 Aug 2017 16:55

Butzei wrote:It only occures on higher server load with multiple requests executed in parallel. So i think it would be hard to build an example project.
If possible, please create a test project and upload it to ftp://ftp.devart.com (credentials: anonymous / yourEmail) so that we can reproduce and investigate the problem.
Shalex
Devart Team
 
Posts: 7705
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle