{"record":{"id":"f705ed7050cb4adc","repo":"dotnet/wpf","slug":"sr-format-sr-membernotallowedduringtransaction-commitnew-f705ed","errorCode":null,"errorMessage":"SR.Format(SR.MemberNotAllowedDuringTransaction, \"CommitNew\", \"EditItem\")","messagePattern":"SR\\.Format\\(SR\\.MemberNotAllowedDuringTransaction, \"CommitNew\", \"EditItem\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs","lineNumber":825,"sourceCode":"\n            // raise events as if the new item appeared in the adjusted position\n            ProcessCollectionChangedWithAdjustedIndex(\n                                        new NotifyCollectionChangedEventArgs(\n                                                NotifyCollectionChangedAction.Add,\n                                                newItem,\n                                                position),\n                                        -1, position);\n        }\n\n        /// <summary>\n        /// Complete the transaction started by <seealso cref=\"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        public void CommitNew()\n        {\n            if (IsEditingItem)\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedDuringTransaction, \"CommitNew\", \"EditItem\"));\n            VerifyRefreshNotDeferred();\n\n            if (_newItem == NoNewItem)\n                return;\n\n            // grouping works differently\n            if (IsGrouping)\n            {\n                CommitNewForGrouping();\n                return;\n            }\n\n            // from the POV of view clients, the new item is moving from its\n            // position adjacent to the placeholder to its real position.\n            // Remember its current position (have to do this before calling EndNew,\n            // because InternalCount depends on \"adding-new\" mode).\n            int fromIndex = 0;\n            switch (NewItemPlaceholderPosition)","sourceCodeStart":807,"sourceCodeEnd":843,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs#L807-L843","documentation":"CommitNew finishes an AddNew transaction, so it cannot run while an EditItem transaction is open. If IsEditingItem is true, ListCollectionView.CommitNew throws InvalidOperationException naming CommitNew and EditItem.","triggerScenarios":"Calling CommitNew() while an EditItem transaction is active (EditItem called, no CommitEdit/CancelEdit yet) — e.g. interleaved add/edit calls on IEditableCollectionView.","commonSituations":"MVVM command handlers where AddNew and EditItem flows overlap; a DataGrid committing a new row while a cell edit transaction is still open due to missing CommitEdit calls.","solutions":["Call CommitEdit() or CancelEdit() to close the EditItem transaction before calling CommitNew","Ensure each AddNew/EditItem is paired with exactly one Commit/Cancel call in the right order","Check IsEditingItem (and IsAddingNew) before invoking CommitNew"],"exampleFix":"// before\ncollectionView.CommitNew(); // throws if EditItem is open\n// after\nvar ecv = (IEditableCollectionView)collectionView;\nif (ecv.IsEditingItem) ecv.CommitEdit();\nif (ecv.IsAddingNew) ecv.CommitNew();","handlingStrategy":"validation","validationCode":"var ecv = (IEditableCollectionView)view;\nif (ecv.IsEditingItem) ecv.CommitEdit();\nif (ecv.IsAddingNew) ecv.CommitNew();","typeGuard":null,"tryCatchPattern":"try { view.CommitNew(); }\ncatch (InvalidOperationException)\n{\n    // an EditItem transaction is open; commit/cancel it first\n}","preventionTips":["Maintain one-transaction-at-a-time discipline: never call AddNew while EditItem is open","Pair every AddNew with CommitNew/CancelNew and every EditItem with CommitEdit/CancelEdit","Check IsEditingItem/IsAddingNew before invoking transactional methods"],"tags":["wpf","data-binding","invalidoperationexception","listcollectionview","transaction"],"backgroundTag":"invalid-state-transition","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"}