{"record":{"id":"36a7022258a4a992","repo":"dotnet/wpf","slug":"sr-format-sr-membernotallowedforview-commitedit","errorCode":null,"errorMessage":"SR.Format(SR.MemberNotAllowedForView, \"CommitEdit\")","messagePattern":"SR\\.Format\\(SR\\.MemberNotAllowedForView, \"CommitEdit\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs","lineNumber":1100,"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 = _collectionView 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 = _collectionView 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":1082,"sourceCodeEnd":1118,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs#L1082-L1118","documentation":"ItemCollection.CommitEdit ends an edit transaction on the current item, but only the active view can perform it. When the collection's view does not implement IEditableCollectionView, the method throws InvalidOperationException with MemberNotAllowedForView(\"CommitEdit\"). This guards IEditableCollectionViewAddNewItem/IEditableCollectionView members that are only meaningful for editable views.","triggerScenarios":"Calling ItemCollection.CommitEdit() when the underlying ICollectionView (e.g. a plain ListCollectionView wrapper over a non-editable source, or a custom view) does not implement IEditableCollectionView — i.e. CanCommitEdit is false.","commonSituations":"Binding an ItemsControl to a source whose default view lacks edit-transaction support, then calling CommitEdit directly on Items or ItemCollection in code; porting code written against a DataGrid/BindingList-based source to a simple IEnumerable source.","solutions":["Check the CanCommitEdit property (or view is IEditableCollectionView) before calling CommitEdit","Cast the view: if (items.CollectionView is IEditableCollectionView ecv) ecv.CommitEdit();","Ensure the ItemsSource is a type whose default view supports editing (e.g. ObservableCollection, or use a CollectionViewSource with an editable source)"],"exampleFix":"// before\nitems.CommitEdit();\n// after\nif (items.CanCommitEdit) { items.CommitEdit(); }","handlingStrategy":"validation","validationCode":"if (items.CanCommitEdit) items.CommitEdit();","typeGuard":"bool canCommit = items.CollectionView is IEditableCollectionView ecv && ecv.CanCommitEdit;","tryCatchPattern":"try { items.CommitEdit(); } catch (InvalidOperationException ex) { /* view does not support edit transactions */ }","preventionTips":["Always check CanCommitEdit before edit-transaction APIs","Verify the ItemsSource type produces an IEditableCollectionView","Keep edit-transaction logic in the view layer where the view type is known"],"tags":["wpf","itemcollection","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-21T21:30:21.729Z"}