{"record":{"id":"97a7446728b7f314","repo":"dotnet/wpf","slug":"throw-new-invalidoperationexception-sr-format-sr-97a744","errorCode":null,"errorMessage":"throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"CancelNew\"));","messagePattern":"throw new InvalidOperationException\\(SR\\.Format\\(SR\\.MemberNotAllowedForView, \"CancelNew\"\\)\\);","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs","lineNumber":482,"sourceCode":"            {\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            }\n        }\n\n        /// <summary>\n        /// Returns true if an </seealso cref=\"IEditableCollectionView.AddNew\"> transaction is in progress.\n        /// </summary>\n        bool IEditableCollectionView.IsAddingNew\n        {\n            get\n            {\n                IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;\n                if (ecv != null)\n                {\n                    return ecv.IsAddingNew;\n                }\n                else\n                {\n                    return false;","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs#L464-L500","documentation":"CollectionViewProxy.CancelNew() forwards to the proxied view's IEditableCollectionView.CancelNew. If the proxied view does not implement IEditableCollectionView (null `ecv` at CollectionViewProxy.cs:482), the proxy throws InvalidOperationException because there is no AddNew transaction machinery to cancel.","triggerScenarios":"Calling CollectionViewProxy.CancelNew() when the wrapped view does not implement IEditableCollectionView, or when no AddNew is possible on that view type.","commonSituations":"Canceling a 'new item' row in a data-bound grid backed by a collection view without edit support; refactoring code that previously bound to ListCollectionView to a custom view; unit tests invoking CancelNew on stub views.","solutions":["Guard with CanCancelNew before calling CancelNew","Ensure the underlying collection's view implements IEditableCollectionView (e.g. use ItemCollection/ListCollectionView-backed sources)","Add IEditableCollectionView support to a custom ICollectionView implementation"],"exampleFix":"// before\nproxy.CancelNew();\n// after\nif (proxy.CanCancelNew)\n{\n    proxy.CancelNew();\n}","handlingStrategy":"validation","validationCode":"if (!proxy.CanCancelNew) return;\nproxy.CancelNew();","typeGuard":"bool SupportsCancelNew(CollectionViewProxy p) => p?.ProxiedView is IEditableCollectionView;","tryCatchPattern":"try { proxy.CancelNew(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"CancelNew\")) { /* nothing to cancel / unsupported view */ }","preventionTips":["Gate CancelNew behind CanCancelNew checks","Keep a single code path for add/cancel transactions so unsupported views never reach it","Test with the actual bound view type, not just ListCollectionView"],"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"}