I have a situation and wonder if someone can advice how to handle this.
In the example below I have 2 orders to process in the CSV file, I will loop through the total items using aCSV.OrderRequest.Items
and the first thing I do is to check if an order already exist, if it does then I reject the order and reduce the total number of items by 1, so the new values of
aCSV.OrderRequest.Items = 1, however the code intended to loop through for 2 times now when I have removed 1 item, its failing when it comes "Next" statement with an exception below
"Collection was modified; enumeration operation may not execute."
For Each aCSV As xCSV In _CSVs
For Each Item As cCSVProductItem In aCSV.OrderRequest.Items
NumOrders = Orders.IsRetailerOrderIdExist(Item.OrderItemNumber)
If (NumOrders.HasValue AndAlso NumOrders.Value > 0) Then
aCSV.RetailerOrderID = NumOrders.Value
'If the order id already exist - SEND THE CANCELLATION DISPATCH NOTFICATION
CreateCancelOrderNotification(GetOrderStatusFileName("REJECTED"), aCSV, Item)
'To make sure the product is on the list,
If CheckIfProductExist(aCSV, Item) Then
'Capture the order and save in the database.
Catch ex As Exception