Unable to remove duplicate item from ContentArea

Ted
Ted
Vote:
 

I have a ContentArea with the same piece of content added multiple times (duplicates).

If I do the following...

myPage.MyContentArea.Items.Remove(contentAreaItem)

...I get an InvalidOperationException saying "Sequence contains more than one matching element", which makes sense.

However, I get the same exception if I do:

myPage.MyContentArea.Items.RemoveAt(0)

Since the Items property is a IList<T> I would have expected the first item to be removed, but instead I get the same InvalidOperationException.

Appreciate any input or bright ideas! :)

#112549
Oct 29, 2014 22:19
Vote:
 
<p>RemoveAt will invoke RemoveContentFragment, which causes the exception, as it will invoka&nbsp;a standard Remove on the collection.</p> <p>A workaround could be to remove the fragment prior to removing the content area item.</p> <pre class="brush:csharp;auto-links:false;toolbar:false" contenteditable="false"> page.MainContentArea.Fragments.RemoveAt(0); page.MainContentArea.Items.RemoveAt(0);</pre> <p>You should probably set IsModified to true as well, since this would&nbsp;have been set had we not manually removed the fragment.</p> <pre class="brush:csharp;auto-links:false;toolbar:false" contenteditable="false">page.MainContentArea.IsModified = true;</pre> <p></p>
#112663
Nov 03, 2014 13:44
Vote:
 
<p>I have the same problem. When calling Items.RemoveAt after calling Fragments.RemoveAt I get an index out of range exception. Using EPiServer CMS 7.16.1</p>
#113893
Dec 01, 2014 12:47
Vote:
 
<p><strong></strong>Did any of you solve this problem?&nbsp;</p>
#142617
Dec 16, 2015 10:30