<p>RemoveAt will invoke RemoveContentFragment, which causes the exception, as it will invoka 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 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>
<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>
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! :)