{"record":{"id":"e8ea941d08885afd","repo":"dotnet/wpf","slug":"throw-new-invalidoperationexception-sr-format-sr-e8ea94","errorCode":null,"errorMessage":"throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"CancelEdit\"));","messagePattern":"throw new InvalidOperationException\\(SR\\.Format\\(SR\\.MemberNotAllowedForView, \"CancelEdit\"\\)\\);","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs","lineNumber":637,"sourceCode":"            {\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"CommitEdit\"));\n            }\n        }\n\n        /// <summary>\n        /// Complete the transaction started by <seealso cref=\"IEditableCollectionView.EditItem\"/>.\n        /// The pending changes (if any) to the item are discarded.\n        /// </summary>\n        void IEditableCollectionView.CancelEdit()\n        {\n            IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;\n            if (ecv != null)\n            {\n                ecv.CancelEdit();\n            }\n            else\n            {\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"CancelEdit\"));\n            }\n        }\n\n        /// <summary>\n        /// Returns true if the view supports the notion of \"pending changes\" on the\n        /// current edit item.  This may vary, depending on the view and the particular\n        /// item.  For example, a view might return true if the current edit item\n        /// implements <seealso cref=\"IEditableObject\"/>, or if the view has special\n        /// knowledge about the item that it can use to support rollback of pending\n        /// changes.\n        /// </summary>\n        bool IEditableCollectionView.CanCancelEdit\n        {\n            get\n            {\n                IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;\n                if (ecv != null)\n                {","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs#L619-L655","documentation":"CollectionViewProxy.CancelEdit() discards pending item changes by delegating to IEditableCollectionView.CancelEdit on the proxied view. When the wrapped view does not implement that interface (null `ecv` at CollectionViewProxy.cs:637), the proxy throws InvalidOperationException because this view does not support canceling edits.","triggerScenarios":"Calling CancelEdit on a CollectionViewProxy whose ProxiedView is not IEditableCollectionView.","commonSituations":"Escaping row edits in a data-bound grid backed by an unsupported collection; view-models that always call CancelEdit in error handlers; switching collection implementations without updating view code.","solutions":["Check CanCancelEdit before calling CancelEdit","Back the view with a collection whose view implements IEditableCollectionView","Implement IEditableCollectionView on custom views that need edit transactions"],"exampleFix":"// before\nproxy.CancelEdit();\n// after\nif (proxy.CanCancelEdit)\n{\n    proxy.CancelEdit();\n}","handlingStrategy":"validation","validationCode":"if (!proxy.CanCancelEdit) return;\nproxy.CancelEdit();","typeGuard":"bool SupportsCancelEdit(CollectionViewProxy p) => p?.ProxiedView is IEditableCollectionView;","tryCatchPattern":"try { proxy.CancelEdit(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"CancelEdit\")) { /* unsupported view; discard changes manually */ }","preventionTips":["Check CanCancelEdit before canceling","Keep snapshots of edited objects as a manual rollback fallback","Use ObservableCollection<T>/ListCollectionView when edit transactions are needed"],"tags":["wpf","collection-view","invalidoperation","edit-transaction"],"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"}