{"record":{"id":"0bbc65486303b7e6","repo":"dotnet/wpf","slug":"throw-new-invalidoperationexception-sr-format-sr-0bbc65","errorCode":null,"errorMessage":"throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"RemoveAt\"));","messagePattern":"throw new InvalidOperationException\\(SR\\.Format\\(SR\\.MemberNotAllowedForView, \"RemoveAt\"\\)\\);","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs","lineNumber":563,"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 = ProxiedView 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 = 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        }","sourceCodeStart":545,"sourceCodeEnd":581,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs#L545-L581","documentation":"CollectionViewProxy.RemoveAt(index) requires the proxied view to implement IEditableCollectionView, which owns removal-by-index. When the wrapped view lacks that interface (null `ecv` at CollectionViewProxy.cs:563), the proxy throws InvalidOperationException indicating RemoveAt is not allowed for this view.","triggerScenarios":"Calling RemoveAt on a CollectionViewProxy whose ProxiedView implements neither IEditableCollectionView nor an equivalent removal path (the `ecv` cast fails).","commonSituations":"Removing items from a read-only or fixed-size collection's view; views over arrays or immutable collections; data-binding controls that assume editable views.","solutions":["Check the view supports removal (cast ProxiedView as IEditableCollectionView != null) before RemoveAt","Remove the item from the underlying collection instead of the view, then let change notifications update the view","Switch the source collection to a mutable type whose view supports IEditableCollectionView"],"exampleFix":"// before\nproxy.RemoveAt(0);\n// after\nvar ecv = proxy.ProxiedView as IEditableCollectionView;\nif (ecv != null)\n{\n    proxy.RemoveAt(0);\n}","handlingStrategy":"validation","validationCode":"if (proxy.ProxiedView is IEditableCollectionView) { proxy.RemoveAt(index); }","typeGuard":"bool SupportsRemoveAt(CollectionViewProxy p) => p?.ProxiedView is IEditableCollectionView;","tryCatchPattern":"try { proxy.RemoveAt(index); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"RemoveAt\")) { /* fall back to removing from the source collection */ }","preventionTips":["Remove items from the underlying collection and let change notifications update the view","Check CanRemove before index-based removal","Avoid binding editable UI to read-only or immutable source collections"],"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"}