{"record":{"id":"3fe40c302c05fc79","repo":"dotnet/wpf","slug":"sr-format-sr-membernotallowedforview-remove","errorCode":null,"errorMessage":"SR.Format(SR.MemberNotAllowedForView, \"Remove\")","messagePattern":"SR\\.Format\\(SR\\.MemberNotAllowedForView, \"Remove\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs","lineNumber":1059,"sourceCode":"            else\n            {\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"RemoveAt\"));\n            }\n        }\n\n        /// <summary>\n        /// Remove the given item from the underlying collection.\n        /// </summary>\n        void    IEditableCollectionView.Remove(object item)\n        {\n            IEditableCollectionView ecv = _collectionView as IEditableCollectionView;\n            if (ecv != null)\n            {\n                ecv.Remove(item);\n            }\n            else\n            {\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"Remove\"));\n            }\n        }\n\n        #endregion Removing items\n\n        #region Transactional editing of an item\n\n        /// <summary>\n        /// Begins an editing transaction on the given item.  The transaction is\n        /// completed by calling either <seealso cref=\"IEditableCollectionView.CommitEdit\"/> or\n        /// <seealso cref=\"IEditableCollectionView.CancelEdit\"/>.  Any changes made to the item during\n        /// the transaction are considered \"pending\", provided that the view supports\n        /// the notion of \"pending changes\" for the given item.\n        /// </summary>\n        void    IEditableCollectionView.EditItem(object item)\n        {\n            IEditableCollectionView ecv = _collectionView as IEditableCollectionView;\n            if (ecv != null)","sourceCodeStart":1041,"sourceCodeEnd":1077,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs#L1041-L1077","documentation":"ItemCollection.Remove throws InvalidOperationException(SR.MemberNotAllowedForView, \"Remove\") when the underlying view does not implement IEditableCollectionView. The wrapper delegates removal to the view and requires editing support.","triggerScenarios":"Calling items.Remove(item) when ItemsSource's view is not an IEditableCollectionView.","commonSituations":"Delete-item commands against a read-only or minimal collection source; swapping ItemsSource implementations at runtime so previously-working Remove calls start failing.","solutions":["Ensure ItemsSource's view implements IEditableCollectionView (e.g. bind to ObservableCollection<T>).","Remove the item from the underlying source collection directly instead.","Feature-check before calling, e.g. verify `items.CollectionView is IEditableCollectionView`."],"exampleFix":"// before\nitems.Remove(selectedItem);\n// after\nvar oc = (ObservableCollection<MyItem>)itemsControl.ItemsSource;\noc.Remove(selectedItem);","handlingStrategy":"validation","validationCode":"if (items.CollectionView is IEditableCollectionView)\n    items.Remove(item);\nelse\n    ((IList)itemsControl.ItemsSource).Remove(item);","typeGuard":"static bool CanRemove(ItemCollection c) => c.CollectionView is IEditableCollectionView;","tryCatchPattern":"try { items.Remove(item); }\ncatch (InvalidOperationException) { ((IList)itemsControl.ItemsSource).Remove(item); }","preventionTips":["Bind to ObservableCollection<T> so Remove is supported","Remove from the source collection when the view is not editable","Guard view-specific members with IEditableCollectionView checks"],"tags":["wpf","itemcollection","invalidoperationexception","remove"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}