Operation is not valid due to the current state of the object

Never in all the years i worked with C# i seen this warning. My code is simple, so the big question is. What type of state is my List in? And why does this not happen to my second list that is100% equal?

// header section
public List<Item> SpecificItem = new List<Item>();
public List<Item> RandomeXItems= new List<Item>();

// in some object or Start void
 if (RandomeXItems.Count > 0)
int MaxId = RandomeXItems.Max(i => i.ItemID); //  InvalidOperationException

 if (SpecificItem.Count > 0)
int MaxId = SpecificItem.Max(i => i.ItemID); // no errors and working

Make sense? (both lists are empty for test, same if items in them also, makes no difference)

Hi

There’s a typo in line 8… RandomeXItems

Hope this helps

Hi Song, thanks but unfortunately that was just type error on this forum. I manage to solve the issue, by removing the script on the object and reattach. I wonder if this is some type of serializing issue. Ohh well another ghost down the drain, hope i don’t see it again.