SaaS CMS has officially launched! Learn more now.

After deletion of LineItem from Cart, exception thrown during Migrate event after login


I'm using the VNext workflow on Commerce 9.22. I'm having the following issue:

- An anonymous user fills a cart

- The users removes a LineItem

- The user logs in, the transferal/merging of the cart automatically takes place but throws the following exception:

Parameter name: index

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: ArgumentOutOfRange_Index
Parameter name: index

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: ArgumentOutOfRange_Index
Parameter name: index]
   Mediachase.Commerce.Storage.StorageCollectionBase.System.Collections.IList.get_Item(Int32 index) +183
   Mediachase.Commerce.Storage.MetaStorageCollectionBase`1.get_Item(Int32 index) +13
   Mediachase.Commerce.Orders.Cart.UpdateLineItemIndexesInShipment(Shipment shipment, OrderForm fromOrderForm, OrderForm toOrderForm) +156
   Mediachase.Commerce.Orders.Cart.Add(OrderGroup orderGroup, Boolean lineItemRollup) +833
   EPiServer.Business.Commerce.HttpModules.ProfileModule.MigrateCart(String cartName, Guid contactId, String anonymousId, IMarket market) +194
   EPiServer.Business.Commerce.HttpModules.ProfileModule.MigrateShoppingCart(CustomerContact customerContact, String anonymousID) +479
   EPiServer.Business.Commerce.HttpModules.ProfileModule.Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs pe) +614
   System.Web.Profile.ProfileModule.OnEnter(Object source, EventArgs eventArgs) +9951361
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

For removing the lineItem from the Cart i'm using the following code:

var lineItem = CartHelper.LineItems.FirstOrDefault(l => l.LineItemId ==;

I've tried to remove the line where i remove the LineItem from the shipment, but with no effect. After the users removes the lineItem the cart is displayed like it should, and in CommerceManager the cart also contains the correct products.

Does anyone have any suggestions?

Oct 06, 2016 14:21


You should use this instead to remove a LineItem from cart:

PurchaseOrderManager.RemoveLineItemFromOrder(cartHelper.Cart, lineItemId);

This will take care of everything for you.



Oct 06, 2016 17:49

Thanks, works like a charm!

Oct 07, 2016 8:46
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.