Don't miss out Virtual Happy Hour this Friday (April 26).
Try our conversational search powered by Generative AI!
AI OnAI Off
Don't miss out Virtual Happy Hour this Friday (April 26).
Oct 27, 2017
Nov 27, 2017
CMS Core
Closed, Fixed and tested
Steps to reproduce
private void RemoveAllContentAreaItems(ContentArea contentArea) { int contentAreaItemsCount = contentArea.Count; for (int i = 0; i < contentAreaItemsCount; i++) { try { contentArea.Items.RemoveAt(0); } catch (Exception e) { Logger.Error("Could not remove block from Content Area", e); } } contentArea.IsModified = true; }
Expected: Can delete items from a content area programmatically.
Actual: Get the following exception:
System.InvalidOperationException: Sequence contains more than one matching element at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate) at EPiServer.Core.ContentArea.RemoveContentFragment(ContentReference contentlink) at EPiServer.Core.ContentArea.ModifyCollectionInternally(Action modification) at EPiServer.Core.ContentArea.OnContentAreaItemsChanged(Object sender, NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index)