U4-1974 - Setting ContentType.MasterContentType error

Created by Stephen Rogers 21 Mar 2013, 13:07:09 Updated by Morten Christensen 21 Mar 2013, 19:47:43

uSiteBuilder allow you to change the inheritance of doc types. When setting the MasterContentType Umbraco is throwing a

'''Collection was modified; enumeration operation may not execute.'''

The culprit seems to be that set_MasterContentType calls

                {code:lang=c#}

foreach (var mct in MasterContentTypes) { RemoveParentContentType(mct); }

and that method calls MasterContentTypes.Remove(parentContentTypeId); modifying the enumerable.

Stack trace:

[InvalidOperationException: Collection was modified; enumeration operation may not execute.] System.Collections.Generic.Enumerator.MoveNextRare() +12531803 umbraco.cms.businesslogic.ContentType.set_MasterContentType(Int32 value) +208 Vega.USiteBuilder.DocumentTypeManager.SynchronizeDocumentType(Type typeDocType, Type baseTypeDocType) +483 Vega.USiteBuilder.DocumentTypeManager.SynchronizeDocumentTypes(Type baseTypeDocType) +146 Vega.USiteBuilder.DocumentTypeManager.SynchronizeDocumentTypes(Type baseTypeDocType) +157 Vega.USiteBuilder.DocumentTypeManager.SynchronizeDocumentTypes(Type baseTypeDocType) +157 Vega.USiteBuilder.DocumentTypeManager.SynchronizeDocumentTypes(Type baseTypeDocType) +157 Vega.USiteBuilder.DocumentTypeManager.Synchronize() +56 Vega.USiteBuilder.UmbracoManager.SynchronizeAllDocumentTypes() +86 kelvinDigital.USiteBuilderAdmin.uSiteBuilderAdmin.btnSync_Click(Object sender, EventArgs e) +104 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +

Comments

Morten Christensen 21 Mar 2013, 19:44:46

Since there can only be one master (the get of MasterContentType returns MasterContentTypes[0] and theres not really a way to add more then one unless you add something directly to the database) it seems odd to loop through the list and remove everything, so I've changed it to this instead:

if (MasterContentTypes.Count > 0) { var masterId = MasterContentTypes[0]; RemoveParentContentType(masterId); }

AddParentContentType(value);

So: remove the current master if one exists and add the new master id set on the MasterContentType property.


Morten Christensen 21 Mar 2013, 19:47:43

Fixed in changeset 37fbf9397149


Priority: Normal

Type: Bug

State: Fixed

Assignee: Morten Christensen

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.0.0, 6.0.1, 6.0.2

Due in version: 6.0.3

Sprint:

Story Points:

Cycle: