Try our conversational search powered by Generative AI!

Unable to remove duplicate item from ContentArea


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

If I do the following...


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

However, I get the same exception if I do:


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! :)

Oct 29, 2014 22:19
<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>
Nov 03, 2014 13:44
<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>
Dec 01, 2014 12:47
<p><strong></strong>Did any of you solve this problem?&nbsp;</p>
Dec 16, 2015 10:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.