dotnet/wpf · error · InvalidOperationException
SR.Format(SR.MemberNotAllowedDuringTransaction…
Error message
SR.Format(SR.MemberNotAllowedDuringTransaction, "CommitNew", "EditItem")
What it means
CommitNew() finalizes an AddNew transaction, but it throws InvalidOperationException if an EditItem transaction is still open. The view supports only one transaction at a time, so committing a new item while an item is being edited is an invalid state transition.
Solutions
- Call CommitEdit() or CancelEdit() before calling CommitNew().
- Guard with IsEditingItem before calling CommitNew and handle the pending edit first.
- Refactor so each UI action manages only one transaction (edit or add) at a time.
- In DataGrid scenarios, let the grid's own commit pipeline run instead of calling CommitNew manually.
Example fix
// before view.EditItem(item); view.AddNew(); view.CommitNew(); // after view.EditItem(item); view.CommitEdit(); view.AddNew(); view.CommitNew();
Defensive patterns
Strategy: validation
Validate before calling
// C# if (view.IsEditingItem) view.CommitEdit(); // or CancelEdit view.CommitNew();
Type guard
bool CanCommitNew(IEditableCollectionView v) => !v.IsEditingItem && v.IsAddingNew;
Try / catch
try { view.CommitNew(); }
catch (InvalidOperationException ex) { Log.Warn("CommitNew blocked by open EditItem transaction", ex); } Prevention
- Treat AddNew and EditItem as exclusive transactions.
- Check IsEditingItem/IsAddingNew before committing.
- Route all commit/cancel calls through one state-aware helper.
When it happens
Trigger: Calling AddNew() then EditItem(...) (without CommitEdit/CancelEdit) and then CommitNew(); or EditItem() implicitly started and an outer code path calls CommitNew.
Common situations: DataGrid row-commit logic interleaved with manual AddNew/EditItem calls; nested handlers where one handler calls CommitNew while a cell edit is still open; missing CommitEdit before switching from edit to add.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- SR.Format(SR.MemberNotAllowedDuringTransaction…
- SR.Format(SR.MemberNotAllowedDuringTransaction…
- SR.Format(SR.MemberNotAllowedDuringTransaction…
- ArgumentNullException(nameof(value))
- (no message) NotSupportedException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/22a4cbb2fa2ae949.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs:649
}
}
// raise events as if the new item appeared in the adjusted position
ProcessCollectionChanged(new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Add,
newItem,
position));
}
/// <summary>
/// Complete the transaction started by <seealso cref="AddNew"/>. The new
/// item remains in the collection, and the view's sort, filter, and grouping
/// specifications (if any) are applied to the new item.
/// </summary>
public void CommitNew()
{
if (IsEditingItem)
throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedDuringTransaction, "CommitNew", "EditItem"));
VerifyRefreshNotDeferred();
if (_newItem == NoNewItem)
return;
// commit the new item
ICancelAddNew ican = InternalList as ICancelAddNew;
IEditableObject ieo;
BindingOperations.AccessCollection(InternalList,
() =>
{
ProcessPendingChanges();
if (ican != null)
{
ican.EndNew(_newItemIndex);
}View on GitHub (pinned to 81131a70a4)