{"record":{"id":"0dceae711e55a7ba","repo":"dotnet/wpf","slug":"throw-new-invalidoperationexception-sr-format-sr-0dceae","errorCode":null,"errorMessage":"throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"Remove\"));","messagePattern":"throw new InvalidOperationException\\(SR\\.Format\\(SR\\.MemberNotAllowedForView, \"Remove\"\\)\\);","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs","lineNumber":579,"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 = ProxiedView 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 = ProxiedView as IEditableCollectionView;\n            if (ecv != null)","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs#L561-L597","documentation":"CollectionViewProxy.Remove(item) forwards to the proxied view's IEditableCollectionView.Remove. If the wrapped view does not implement that interface (null `ecv` at CollectionViewProxy.cs:579), the proxy throws InvalidOperationException because the view cannot remove items.","triggerScenarios":"Calling Remove on a CollectionViewProxy wrapping a view without IEditableCollectionView support (read-only source collections, custom views).","commonSituations":"Deleting the selected row in a ItemsControl bound to a non-editable collection; migrating from ObservableCollection to a custom/immutable source; view-model code that assumes all views support Remove.","solutions":["Verify support via ProxiedView as IEditableCollectionView (or CanRemove) before calling Remove","Mutate the underlying collection directly and rely on INotifyCollectionChanged to refresh the view","Back the binding with a collection type whose default view implements IEditableCollectionView"],"exampleFix":"// before\nproxy.Remove(selectedItem);\n// after\nif (proxy.CanRemove)\n{\n    proxy.Remove(selectedItem);\n}","handlingStrategy":"validation","validationCode":"if (!proxy.CanRemove) return;\nproxy.Remove(item);","typeGuard":"bool SupportsRemove(CollectionViewProxy p) => p?.ProxiedView is IEditableCollectionView;","tryCatchPattern":"try { proxy.Remove(item); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Remove\")) { ((IList)sourceCollection).Remove(item); }","preventionTips":["Prefer mutating the source collection directly for maximum compatibility","Check CanRemove / cast ProxiedView as IEditableCollectionView first","Document which view types your view-model requires"],"tags":["wpf","collection-view","invalidoperation","item-removal"],"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"}