quick Umbraco V7 question. I'm trying to programmatically remove a load of Vorto properties from a V7 site prior to upgrading, however I keep hitting 'Collection was modified; enumeration operation may not execute.' error when running the following code:
var contentTypes = _contentTypeService.GetAllContentTypes();
foreach (var cts in contentTypes.Where(x => x.Id != 10546))
{
var vortoPropsToDelete = cts.PropertyTypes.Where(x => x.PropertyEditorAlias == "Our.Umbraco.Vorto");
foreach (var vortoProp in vortoPropsToDelete)
{
cts.RemovePropertyType(vortoProp.Alias);
}
_contentTypeService.Save(cts);
}
I can't work out were I'm going wrong...
Umbraco v7's GetAllContentTypes method returns a
System.Collections.Generic.IEnumerable<System.Guid>type and you are trying to update your GetAllContentTypes collection before you are finished iterating, hence you see this error.Try to convert your collection to a list, update your code for this and that should work.