{"record":{"id":"712274298e1aefd6","repo":"dotnet/wpf","slug":"throw-new-invalidoperationexception-sr-format-sr-712274","errorCode":null,"errorMessage":"throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"CommitEdit\"));","messagePattern":"throw new InvalidOperationException\\(SR\\.Format\\(SR\\.MemberNotAllowedForView, \"CommitEdit\"\\)\\);","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs","lineNumber":620,"sourceCode":"            {\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"EditItem\"));\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 committed.\n        /// </summary>\n        void IEditableCollectionView.CommitEdit()\n        {\n            IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;\n            if (ecv != null)\n            {\n                ecv.CommitEdit();\n            }\n            else\n            {\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            }","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs#L602-L638","documentation":"CollectionViewProxy.CommitEdit() completes a pending edit transaction by delegating to the proxied view's IEditableCollectionView.CommitEdit. If the wrapped view lacks that interface (null `ecv` at CollectionViewProxy.cs:620), the proxy throws InvalidOperationException since there is no edit transaction support.","triggerScenarios":"Calling CommitEdit on a CollectionViewProxy wrapping a non-IEditableCollectionView view, including cases where no edit is in progress on an unsupported view.","commonSituations":"Committing grid edits on DataBinding over read-only or custom collections; code paths shared between editable and non-editable views; automated UI tests calling CommitEdit unconditionally.","solutions":["Guard with CanCommitEdit before calling CommitEdit","Ensure the view is an IEditableCollectionView (e.g. bind to ObservableCollection<T> viewed through ListCollectionView)","Implement IEditableCollectionView in custom view classes"],"exampleFix":"// before\nproxy.CommitEdit();\n// after\nif (proxy.CanCommitEdit)\n{\n    proxy.CommitEdit();\n}","handlingStrategy":"validation","validationCode":"if (!proxy.CanCommitEdit) return;\nproxy.CommitEdit();","typeGuard":"bool SupportsCommitEdit(CollectionViewProxy p) => p?.ProxiedView is IEditableCollectionView;","tryCatchPattern":"try { proxy.CommitEdit(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"CommitEdit\")) { /* unsupported view; commit via object model */ }","preventionTips":["Pair every EditItem with CanCommitEdit-guarded CommitEdit","Bind grids only to IEditableCollectionView-backed views","Wrap commit/cancel in a helper that no-ops when unsupported"],"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"}