"Collection was modified" error in Commerce Engine log

  • The issue occurs when the Components collection of any Catalog Entity (SellableItem, Category or Catalog) is modified during serialization and writing of Catalog Entities into the response body.

    When the enumerator of Catalog Entity OData presentation is used, its version is compared with version of the Components collection on each iteration and, if they are not equal, the collection was modified exception is thrown. The stack trace in Commerce log files is as follows:

    ERROR Connection id ""0HLM9N12Q3EI6"", Request id ""0HLM9N12Q3EI6:00000003"": An unhandled exception was thrown by the application.
    System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
       at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
       at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
       at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
       at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataWriter writer, ODataSerializerContext writeContext)
       at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteExpandedNavigationProperty(KeyValuePair`2 navigationPropertyToExpand, EntityInstanceContext entityInstanceContext, ODataWriter writer)
       at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteExpandedNavigationProperties(IDictionary`2 navigationPropertiesToExpand, EntityInstanceContext entityInstanceContext, ODataWriter writer)
       at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteEntry(Object graph, ODataWriter writer, ODataSerializerContext writeContext)
       at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataWriter writer, ODataSerializerContext writeContext)
       at Microsoft.AspNetCore.OData.Formatter.ODataOutputFormatter.WriteResponseBody(OutputFormatterWriteContext context)
       at System.Threading.Tasks.Task.Execute()
  • To fix the problem, download the patch Sitecore.Support.362689 and follow the instructions in the readme file.

    To get a solution for Sitecore XP versions, which are not listed at the link above, contact Sitecore Support. 

Applies to:

CMS 9.0 Update-2, Sitecore Experience Commerce 9.0 Update-3

November 15, 2019
November 15, 2019

Reference number:

362689, 362671, 327128