Failed to call hook 'OnEntityDeath' on plugin 'Backpacks v3.0.2' (InvalidOperationException: Collection was modified; enumeration operation may not execute.)This is the code that is failing:foreach (var item in _itemContainer.itemList)
{
item.Remove();
item.DoRemove();
}
I had this same problem on a plugin I made. Basically, the error is saying that your trying to iterate through a data structure and change that data structure at the same time. Once you change it (item.remove()), you can no longer continue enumeration.
The solution is to iterate through _itemContainer.itemList.ToList() instead. Then, search for the item to remove that matches some unique key in your data structure. This is how I did it in a similar block of code:
foreach (var pl in pd.playerLocks.ToList())
{
if (pl.status == "InProgress" || pl.status == "InProgress2")
{
var plUpdate = pd.playerLocks.Single(r => r.lockID == pl.lockID);
plUpdate.status = "Cooldown";
plUpdate.expTime = DateTime.Now.AddSeconds(config.BypassFailureCooldownTime).ToString();
}
}