Collection was modified; enumeration operation may not execute.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 2 años
Hello,

I have a lot of error with this topic "Collection was modified; enumeration operation may not execute.". but I don't know what happened in back.
Error detail is:
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at System.Linq.Enumerable.Contains[TSource](IEnumerable`1 source, TSource value, IEqualityComparer`1 comparer)
   at Nop.Services.Cms.WidgetPluginManager.<>c__DisplayClass2_0.<<LoadActivePluginsAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.Linq.AsyncEnumerable.WhereEnumerableAsyncIteratorWithTask`1.MoveNextCore() in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Where.cs:line 277
   at System.Linq.AsyncIteratorBase`1.MoveNextAsync() in /_/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncIterator.cs:line 77
   at System.Linq.AsyncIteratorBase`1.MoveNextAsync() in /_/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncIterator.cs:line 77
   at System.Linq.AsyncEnumerable.<ToListAsync>g__Core|620_0[TSource](IAsyncEnumerable`1 source, CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToList.cs:line 36
   at System.Linq.AsyncEnumerable.<ToListAsync>g__Core|620_0[TSource](IAsyncEnumerable`1 source, CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToList.cs:line 36
   at Nop.Services.Cms.WidgetPluginManager.LoadActivePluginsAsync(Customer customer, Int32 storeId, String widgetZone)
   at Nop.Web.Areas.Admin.Factories.WidgetModelFactory.PrepareRenderWidgetModelsAsync(String widgetZone, Object additionalData)
   at Nop.Web.Areas.Admin.Components.AdminWidgetViewComponent.InvokeAsync(String widgetZone, Object additionalData)
   at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.InvokeAsyncCore(ObjectMethodExecutor executor, ViewComponentContext context)
   at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.InvokeAsync(ViewComponentContext context)
   at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper.InvokeCoreAsync(ViewComponentDescriptor descriptor, Object arguments)
   at AspNetCore.Areas_Admin_Views_Product__CreateOrUpdate_ProductAttributes_Combinations.ExecuteAsync() in C:\Inetpub\vhosts\asanmed.com\httpdocs\Areas\Admin\Views\Product\_CreateOrUpdate.ProductAttributes.Combinations.cshtml:line 3
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.RenderPartialCoreAsync(String partialViewName, Object model, ViewDataDictionary viewData, TextWriter writer)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.PartialAsync(String partialViewName, Object model, ViewDataDictionary viewData)
   at AspNetCore.Areas_Admin_Views_Product__CreateOrUpdate_ProductAttributes.<ExecuteAsync>b__14_2() in C:\Inetpub\vhosts\asanmed.com\httpdocs\Areas\Admin\Views\Product\_CreateOrUpdate.ProductAttributes.cshtml:line 16
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.GetChildContentAsync(Boolean useCachedResult, HtmlEncoder encoder)
   at Nop.Web.Framework.TagHelpers.Admin.NopTabTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, Int32 i, Int32 count)
   at AspNetCore.Areas_Admin_Views_Product__CreateOrUpdate_ProductAttributes.<ExecuteAsync>b__14_0() in C:\Inetpub\vhosts\asanmed.com\httpdocs\Areas\Admin\Views\Product\_CreateOrUpdate.ProductAttributes.cshtml:line 16
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.GetChildContentAsync(Boolean useCachedResult, HtmlEncoder encoder)
   at Nop.Web.Framework.TagHelpers.Admin.NopTabsTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, Int32 i, Int32 count)
   at AspNetCore.Areas_Admin_Views_Product__CreateOrUpdate_ProductAttributes.ExecuteAsync() in C:\Inetpub\vhosts\asanmed.com\httpdocs\Areas\Admin\Views\Product\_CreateOrUpdate.ProductAttributes.cshtml:line 12
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.RenderPartialCoreAsync(String partialViewName, Object model, ViewDataDictionary viewData, TextWriter writer)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.PartialAsync(String partialViewName, Object model, ViewDataDictionary viewData)
   at AspNetCore.Areas_Admin_Views_Product__CreateOrUpdate.<>c__DisplayClass45_0.<<ExecuteAsync>b__9>d.MoveNext() in C:\Inetpub\vhosts\asanmed.com\httpdocs\Areas\Admin\Views\Product\_CreateOrUpdate.cshtml:line 82
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.GetChildContentAsync(Boolean useCachedResult, HtmlEncoder encoder)
   at Nop.Web.Framework.TagHelpers.Admin.NopCardTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, Int32 i, Int32 count)
   at AspNetCore.Areas_Admin_Views_Product__CreateOrUpdate.<>c__DisplayClass45_0.<<ExecuteAsync>b__3>d.MoveNext() in C:\Inetpub\vhosts\asanmed.com\httpdocs\Areas\Admin\Views\Product\_CreateOrUpdate.cshtml:line 82
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.SetOutputContentAsync()
   at AspNetCore.Areas_Admin_Views_Product__CreateOrUpdate.ExecuteAsync() in C:\Inetpub\vhosts\asanmed.com\httpdocs\Areas\Admin\Views\Product\_CreateOrUpdate.cshtml:line 70
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.RenderPartialCoreAsync(String partialViewName, Object model, ViewDataDictionary viewData, TextWriter writer)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.PartialAsync(String partialViewName, Object model, ViewDataDictionary viewData)
   at AspNetCore.Areas_Admin_Views_Product_Edit.<ExecuteAsync>b__22_0() in C:\Inetpub\vhosts\asanmed.com\httpdocs\Areas\Admin\Views\Product\Edit.cshtml:line 48
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.GetChildContentAsync(Boolean useCachedResult, HtmlEncoder encoder)
   at Microsoft.AspNetCore.Mvc.TagHelpers.RenderAtEndOfFormTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, Int32 i, Int32 count)
   at AspNetCore.Areas_Admin_Views_Product_Edit.ExecuteAsync() in C:\Inetpub\vhosts\asanmed.com\httpdocs\Areas\Admin\Views\Product\Edit.cshtml:line 7
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
   at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at WebMarkupMin.AspNetCore5.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, Boolean useMinification, Boolean useCompression)
   at WebMarkupMin.AspNetCore5.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, Boolean useMinification, Boolean useCompression)
   at WebMarkupMin.AspNetCore5.WebMarkupMinMiddlewareBase.Invoke(HttpContext context)
   at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 125
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Nop.Services.Authentication.AuthenticationMiddleware.InvokeAsync(HttpContext context)
   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.Services.Installation.InstallUrlMiddleware.InvokeAsync(HttpContext context, IWebHelper webHelper)
   at Nop.Services.Common.KeepAliveMiddleware.InvokeAsync(HttpContext context, IWebHelper webHelper)
   at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.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>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

This error occurred in all pages.
Can anyone helps me to resolve this problem?

Thanks in advance
Hace 2 años
What version of nopCommerce ?
Do you have any custom plugins  ?
Hace 2 años
Yidna wrote:
What version of nopCommerce ?
Do you have any custom plugins  ?



nopCommerce version 4.40.4
Yes, I have custom plugins.
Hace 2 años
What is the WidgetPluginManager ?
Maybe it has some problems
Is this an ongoing problem of once off ?
If ongoing you could uninstall that plugin and see if you still have the issue
Hace 2 años
There are some plugins but I have some critical plugin that I can not uninstall them.

I developed most of the plugins myself, but the problem is that this error does not have special conditions that can be debugged.
The big problem is that the details of the errors do not show me much to fix.
Hace 2 años
mohsen_r wrote:
Collection was modified; enumeration operation may not execute.

The problem could be that you will have a foreach construct or similar iterating  through a collection.
While you are going through collection you don’t find an element and so you .Add or .Remove or you update / change the collection in some way before you have finished iterating

You cannot change the collection while you are doing the above.
All you can do is note that you need to change the collection and do it after the above is completed
-  I usually set a Boolean flag to that tells me later I need to add or remove the element

Another option would be to create a new collection as you iterate.
Hace 2 años
Thank you

I think I should check the plugins again.
Hace 1 año
Hy. have you solved your problem??? we have a same conditions... it seem to be more frequently when the website is in big load.... we never experienced it in test enviroment... but when we switch in production the problem began.....

We also have some custom developed plug-in... but the strange thing is that only sometimes the problem appear.... so not a fixed issue in code... but something related to the status of the website in that moment....
Hace 1 año
As mentioned above,  you cannot change the collection while you are iterating it.  Check the call stack in the error message.  Check your custom code.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.