{"record":{"id":"6c1ac2d74731c571","repo":"dotnet/wpf","slug":"sr-format-sr-membernotallowedforview-removeat","errorCode":null,"errorMessage":"SR.Format(SR.MemberNotAllowedForView, \"RemoveAt\")","messagePattern":"SR\\.Format\\(SR\\.MemberNotAllowedForView, \"RemoveAt\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs","lineNumber":1043,"sourceCode":"                }\n            }\n        }\n\n        /// <summary>\n        /// Remove the item at the given index from the underlying collection.\n        /// The index is interpreted with respect to the view (not with respect to\n        /// the underlying collection).\n        /// </summary>\n        void    IEditableCollectionView.RemoveAt(int index)\n        {\n            IEditableCollectionView ecv = _collectionView as IEditableCollectionView;\n            if (ecv != null)\n            {\n                ecv.RemoveAt(index);\n            }\n            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        }","sourceCodeStart":1025,"sourceCodeEnd":1061,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs#L1025-L1061","documentation":"ItemCollection.RemoveAt throws InvalidOperationException(SR.MemberNotAllowedForView, \"RemoveAt\") when the underlying view does not implement IEditableCollectionView, which is required for index-based removal through the wrapper. The collection forwards the call only when the view supports editing.","triggerScenarios":"Calling items.RemoveAt(index) when ItemsSource's view is not an IEditableCollectionView (e.g. ItemsSource bound to a source with a non-editable default view).","commonSituations":"Deleting rows in a list UI whose ItemsSource is a plain IEnumerable or a custom collection view; code tested against ObservableCollection later pointed at a different source.","solutions":["Bind ItemsSource to an ObservableCollection<T> or another source whose view implements IEditableCollectionView.","Guard with `items.IsEditingSupported`/CanRemove checks before calling RemoveAt.","Remove from the source collection directly (it will propagate via collection-change notifications) when the view doesn't support RemoveAt."],"exampleFix":"// before\nitems.RemoveAt(selectedIndex);\n// after\nvar oc = (ObservableCollection<MyItem>)itemsControl.ItemsSource;\noc.RemoveAt(selectedIndex);","handlingStrategy":"validation","validationCode":"if (items.CollectionView is IEditableCollectionView && index >= 0 && index < items.Count)\n    items.RemoveAt(index);\nelse\n    ((IList)itemsControl.ItemsSource).RemoveAt(index);","typeGuard":"static bool CanRemoveAt(ItemCollection c) => c.CollectionView is IEditableCollectionView;","tryCatchPattern":"try { items.RemoveAt(i); }\ncatch (InvalidOperationException) { ((IList)itemsControl.ItemsSource).RemoveAt(i); }","preventionTips":["Validate index against Count first","Prefer removing from the source ObservableCollection directly","Feature-test the view before calling edit-mode members"],"tags":["wpf","itemcollection","invalidoperationexception","removeat"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}