Try our conversational search powered by Generative AI!

Migrate carts in profile module does not work

Vote:
 

Having some issues with the ProfileModule, specifically the MigrateCarts method. 

Scenario is that anonymous user, with a cart, attempts to log in as a authorized user, also with a cart. Thus, the MigrateCarts method will run. However, it fails due to error in this stack trace:

[InvalidOperationException: Collection was modified; enumeration operation may not execute.]
   System.Collections.HashtableEnumerator.MoveNext() +12711378
   Mediachase.Commerce.Extensions.IExtendedPropertiesExtensions.CopyPropertiesFrom(IExtendedProperties target, IExtendedProperties source, Boolean overwrite) +362
   Mediachase.Commerce.Extensions.IExtendedPropertiesExtensions.CopyPropertiesWithOverwriteFrom(IExtendedProperties target, IExtendedProperties source) +39
   Mediachase.Commerce.Orders.OrderForm.UpdateOrderAddress(OrderAddress address, IOrderAddress orderAddress) +585
   Mediachase.Commerce.Orders.OrderForm.SaveOrderAddress(IOrderAddress orderAddress) +292
   Mediachase.Commerce.Orders.Shipment.SetShippingAddress(IOrderAddress value) +478
   Mediachase.Commerce.Orders.Shipment.EPiServer.Commerce.Order.IShipment.set_ShippingAddress(IOrderAddress value) +190
   EPiServer.Commerce.Order.Internal.CartMigrator.MergeTwoShipments(IShipment sourceShipment, IShipment destinationShipment) +94
   EPiServer.Commerce.Order.Internal.CartMigrator.MergeShipments(ICart cart) +449
   EPiServer.Commerce.Order.Internal.CartMigrator.MigrateCarts(Guid sourceCustomerId, Guid destinationCustomerId) +924
   EPiServer.Commerce.Order.ProfileMigrator.MigrateCarts(Guid anonymousId) +388
   EPiServer.Business.Commerce.HttpModules.ProfileModule.Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs pe) +243
   System.Web.Profile.ProfileModule.OnEnter(Object source, EventArgs eventArgs) +328

I've done some debugging, and it seems like the issue is that the same address is sent to the method OrderForm.UpdateOrderAddress(OrderAddress address, IOrderAddress orderAddress) - in other words, address and orderAddress is the same instance.

Specifically, it's this foreach that fails:

      foreach (object key in (IEnumerable) source.Properties.Keys)
      {
        if (overwrite || !target.Properties.ContainsKey(key))
          target.Properties[key] = source.Properties[key];
      }


... which makes sense, because you can't update the same enumerator that you enumerate. So, the issue must be that the same address is passed to UpdateOrderAddress(...). Has anyone had this issue?

EDIT: One more thing, serializable carts is not used. We're still using the old cart system.

#266881
Edited, Nov 17, 2021 16:42
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.