Get Occasional Error tied to Entity Framework

11 months ago
1. Version: nopCommerce Version 4.1
2. Expected Behavior: This happens randomly so the expected behavior would just be for it not to happen.
3. Actual Behavior: Randomly will get the following error: "Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct." and will be unable to view any product pages.  I did research and this appears to be an error with Entity Framework.  Does not happen very often, maybe once or twice a month at most.
4. Steps to reproduce : can't reproduce at will, it just randomly happens.
5. Modifications made to nopCommerce : don't make any modifications to nop, we do all our custom code in plugins.

I did some research and found that this is an intentional exception being thrown.  Is this going to continue to happen in the next version of 4.2 or is there a way to guarantee that operations are thread safe in the new version of .Net or nopCommerce.  It's easy enough to fix as if you restart the site the issue resolves itself I'm more just wondering if there's a way to see if it can stop happening all together.

Thank you!

Sean Flaherty
11 months ago
Would you provide a full stack trace so we can see where it's happening?
(does it always emanate from the same place?)
11 months ago
I cannot say if it's always coming from the same place or not.  Here is the full error from the last time it had happened:

Log level  
Error
Short message  
Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
Full message  
System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.Model.GetDisplayName(Type type)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.Model.FindEntityType(Type type)
   at Microsoft.EntityFrameworkCore.ModelExtensions.FindRuntimeEntityType(IModel model, Type type)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTrackingFromQuery(IEntityType baseEntityType, Object entity, ValueBuffer& valueBuffer, ISet`1 handledForeignKeys)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityTrackingInfo.StartTracking(IStateManager stateManager, Object entity, ValueBuffer& valueBuffer)
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities[TOut,TIn](IEnumerable`1 results, QueryContext queryContext, IList`1 entityTrackingInfos, IList`1 entityAccessors)+MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Nop.Core.Caching.PerRequestCacheManager.Get[T](String key, Func`1 acquire, Nullable`1 cacheTime) in E:\nopCommerce\sources\src\Libraries\Nop.Core\Caching\PerRequestCacheManager.cs:line 62
   at Nop.Services.Catalog.ProductAttributeService.GetProductAttributeMappingsByProductId(Int32 productId) in E:\nopCommerce\sources\src\Libraries\Nop.Services\Catalog\ProductAttributeService.cs:line 200
   at Nop.Web.Factories.ProductModelFactory.<>c__DisplayClass43_0.<PrepareProductAttributeModels>b__0() in C:\TFS Florida\eComm\QA-Nop-4.1\src\eComm.Local.Nop.Source\nopCommerce_4.10\Presentation\Nop.Web\Factories\ProductModelFactory.cs:line 737
   at Nop.Core.Caching.MemoryCacheManager.Get[T](String key, Func`1 acquire, Nullable`1 cacheTime) in E:\nopCommerce\sources\src\Libraries\Nop.Core\Caching\MemoryCacheManager.cs:line 152
   at Nop.Web.Factories.ProductModelFactory.PrepareProductAttributeModels(Product product, ShoppingCartItem updatecartitem) in C:\TFS Florida\eComm\QA-Nop-4.1\src\eComm.Local.Nop.Source\nopCommerce_4.10\Presentation\Nop.Web\Factories\ProductModelFactory.cs:line 740
   at Nop.Web.Factories.ProductModelFactory.PrepareProductDetailsModel(Product product, ShoppingCartItem updatecartitem, Boolean isAssociatedProduct) in C:\TFS Florida\eComm\QA-Nop-4.1\src\eComm.Local.Nop.Source\nopCommerce_4.10\Presentation\Nop.Web\Factories\ProductModelFactory.cs:line 1323
   at Nop.Web.Controllers.ProductController.ProductDetails(Int32 productId, Int32 updatecartitemid) in C:\TFS Florida\eComm\QA-Nop-4.1\src\eComm.Local.Nop.Source\nopCommerce_4.10\Presentation\Nop.Web\Controllers\ProductController.cs:line 179
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 94
   at Nop.Services.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) in E:\nopCommerce\sources\src\Libraries\Nop.Services\Authentication\AuthenticationMiddleware.cs:line 79
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Nop.Core.Http.InstallUrlMiddleware.Invoke(HttpContext context, IWebHelper webHelper) in E:\nopCommerce\sources\src\Libraries\Nop.Core\Http\InstallUrlMiddleware.cs:line 51
   at Nop.Core.Http.KeepAliveMiddleware.Invoke(HttpContext context, IWebHelper webHelper) in E:\nopCommerce\sources\src\Libraries\Nop.Core\Http\KeepAliveMiddleware.cs:line 50
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)

Thank you,

Sean
10 months ago
Can I get an update please?
10 months ago
This is now happening more frequently with several sites that we host, can I get a response please.

Sean
9 months ago
stf09 wrote:
1. Version: nopCommerce Version 4.1
2. Expected Behavior: This happens randomly so the expected behavior would just be for it not to happen.
3. Actual Behavior: Randomly will get the following error: "Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct." and will be unable to view any product pages.  I did research and this appears to be an error with Entity Framework.  Does not happen very often, maybe once or twice a month at most.
4. Steps to reproduce : can't reproduce at will, it just randomly happens.
5. Modifications made to nopCommerce : don't make any modifications to nop, we do all our custom code in plugins.

I did some research and found that this is an intentional exception being thrown.  Is this going to continue to happen in the next version of 4.2 or is there a way to guarantee that operations are thread safe in the new version of .Net or nopCommerce.  It's easy enough to fix as if you restart the site the issue resolves itself I'm more just wondering if there's a way to see if it can stop happening all together.

Thank you!

Sean Flaherty



Do you get any solution for the nopcommerce 4.1? Exact scenario happen to one of our nopcommerce 4.1 project. Though the source code is changed a little and other third party plugins there.
8 months ago
If anybody faces the same problem for nopcommerce 4.1, just need to update the efcore verions of nop.data project from 2.1.1 to 2.1.3

  <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.1.3" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.3" />
  <PackageReference Include="MiniProfiler.EntityFrameworkCore" Version="4.0.133" />