dotnet/wpf · error · InvalidOperationException

SR.Format(SR.MemberNotAllowedForView, "CommitNew")

Error message

SR.Format(SR.MemberNotAllowedForView, "CommitNew")

What it means

ItemCollection.CommitNew throws InvalidOperationException(SR.MemberNotAllowedForView, "CommitNew") when the view does not implement IEditableCollectionView, meaning there is no pending AddNew transaction machinery to commit. It is a forwarding wrapper that requires editing-capable views.

Solutions

  1. Bind ItemsSource to an editing-capable collection (view implements IEditableCollectionView).
  2. Guard with `items.CanCommitNew` before calling CommitNew.
  3. Ensure the same view stays attached across the AddNew..CommitNew transaction.

Example fix

// before
items.CommitNew();
// after
if (items.CanCommitNew)
    items.CommitNew();
Defensive patterns

Strategy: validation

Validate before calling

if (items.CanCommitNew)
    items.CommitNew();

Type guard

static bool CanCommit(ItemCollection c) => c.CollectionView is IEditableCollectionView;

Try / catch

try { items.CommitNew(); }
catch (InvalidOperationException) { /* add transaction not supported; handle manually */ }

Prevention

When it happens

Trigger: Calling items.CommitNew() when ItemsSource's view is not an IEditableCollectionView.

Common situations: Pairing CommitNew/CancelNew UI logic with a data source whose view doesn't support editing; rebinding ItemsSource mid-transaction to an incompatible collection.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/dc2c6572009a47ad. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs:945

            }
        }


        /// <summary>
        /// Complete the transaction started by <seealso cref="IEditableCollectionView.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>
        void    IEditableCollectionView.CommitNew()
        {
            IEditableCollectionView ecv = _collectionView as IEditableCollectionView;
            if (ecv != null)
            {
                ecv.CommitNew();
            }
            else
            {
                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "CommitNew"));
            }
        }

        /// <summary>
        /// Complete the transaction started by <seealso cref="IEditableCollectionView.AddNew"/>.  The new
        /// item is removed from the collection.
        /// </summary>
        void    IEditableCollectionView.CancelNew()
        {
            IEditableCollectionView ecv = _collectionView as IEditableCollectionView;
            if (ecv != null)
            {
                ecv.CancelNew();
            }
            else
            {
                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "CancelNew"));
            }

View on GitHub (pinned to 81131a70a4)