I have this method in the code which causes a fatal error in log4net occasionally. The error message is below, can anyone see how I can handle this? I could include better error messaging for next time, if or when it happens again but I would prefer to correc the code to stop it happening. We are using Castle for configuration so I could possibly use a lifestyle setting of transient but I dont know why this is happening really... Im guessing maybe another thread is using the same code but I dont fully understand why this causes a problem because I'm not removing anything from the list.
eption: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowIn
e resource) at System.Collections.Generic
e() at System.Collections.Generic
public List<ABC> TargetList(IList<Car> cars)
var itemList = new List<ABC>();
foreach (Car car in cars)