{"record":{"id":"9ced0168ffa43e0b","repo":"dotnet/wpf","slug":"throw-new-invalidoperationexception-sr-format-sr-9ced01","errorCode":null,"errorMessage":"throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"CommitNew\"));","messagePattern":"throw new InvalidOperationException\\(SR\\.Format\\(SR\\.MemberNotAllowedForView, \"CommitNew\"\\)\\);","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs","lineNumber":465,"sourceCode":"            }\n        }\n\n\n        /// <summary>\n        /// Complete the transaction started by <seealso cref=\"IEditableCollectionView.AddNew\"/>.  The new\n        /// item remains in the collection, and the view's sort, filter, and grouping\n        /// specifications (if any) are applied to the new item.\n        /// </summary>\n        void IEditableCollectionView.CommitNew()\n        {\n            IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;\n            if (ecv != null)\n            {\n                ecv.CommitNew();\n            }\n            else\n            {\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"CommitNew\"));\n            }\n        }\n\n        /// <summary>\n        /// Complete the transaction started by <seealso cref=\"IEditableCollectionView.AddNew\"/>.  The new\n        /// item is removed from the collection.\n        /// </summary>\n        void IEditableCollectionView.CancelNew()\n        {\n            IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;\n            if (ecv != null)\n            {\n                ecv.CancelNew();\n            }\n            else\n            {\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"CancelNew\"));\n            }","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs#L447-L483","documentation":"CollectionViewProxy wraps another ICollectionView and forwards IEditableCollectionView operations to it. CommitNew throws this InvalidOperationException when the proxied view does not implement IEditableCollectionView (the `ecv` cast in CollectionViewProxy.cs:465 is null), because the underlying view has no notion of a pending AddNew transaction to commit.","triggerScenarios":"Calling CollectionViewProxy.CommitNew() when ProxiedView is a collection view that does not implement IEditableCollectionView (e.g. a plain ListCollectionView-less custom view or a view over a non-editable collection).","commonSituations":"Binding to a collection whose default view lacks edit-transaction support, then calling CommitNew directly on the proxy; custom ICollectionView implementations that didn't implement IEditableCollectionView; sharing view code across collection types where only some support AddNew.","solutions":["Check CanCommitNew (or cast ProxiedView to IEditableCollectionView) before calling CommitNew and skip the call when unsupported","Use a collection whose view implements IEditableCollectionView (e.g. ObservableCollection<T> viewed via ListCollectionView) when you need AddNew/CommitNew transactions","Implement IEditableCollectionView on your custom view if it must support add transactions"],"exampleFix":"// before\nproxy.CommitNew();\n// after\nif (proxy.CanCommitNew)\n{\n    proxy.CommitNew();\n}","handlingStrategy":"validation","validationCode":"if (!proxy.CanCommitNew) return; // IEditableCollectionView missing on proxied view\nproxy.CommitNew();","typeGuard":"bool SupportsEditTransactions(CollectionViewProxy p) => p?.ProxiedView is IEditableCollectionView;","tryCatchPattern":"try { proxy.CommitNew(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"CommitNew\")) { /* view does not support AddNew transactions */ }","preventionTips":["Always check the CanCommitNew/CanCancelNew/CanAddNew capability properties before calling transactional methods","Prefer source collections (ObservableCollection<T>) whose default views implement IEditableCollectionView","Centralize view capability checks in a helper instead of scattering casts"],"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-21T21:30:21.729Z"}