You cannot remove items from a collection which is being used by a
foreach
foreach (var item in itemList)
{
if (item.id == productId)
{
s.Items.Remove(item);
itemList.Remove(item);
break;
}
}
Trying to do that will alter the collection, and that is not allowed.
Change your
foreach
to a
for
loop, running backwards through the collection and it should work.