dotnet/wpf · error · InvalidOperationException

throw new…

Error message

throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "CommitNew"));

What it means

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.

Solutions

  1. Check CanCommitNew (or cast ProxiedView to IEditableCollectionView) before calling CommitNew and skip the call when unsupported
  2. Use a collection whose view implements IEditableCollectionView (e.g. ObservableCollection<T> viewed via ListCollectionView) when you need AddNew/CommitNew transactions
  3. Implement IEditableCollectionView on your custom view if it must support add transactions

Example fix

// before
proxy.CommitNew();
// after
if (proxy.CanCommitNew)
{
    proxy.CommitNew();
}
Defensive patterns

Strategy: validation

Validate before calling

if (!proxy.CanCommitNew) return; // IEditableCollectionView missing on proxied view
proxy.CommitNew();

Type guard

bool SupportsEditTransactions(CollectionViewProxy p) => p?.ProxiedView is IEditableCollectionView;

Try / catch

try { proxy.CommitNew(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("CommitNew")) { /* view does not support AddNew transactions */ }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

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/9ced0168ffa43e0b. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs:465

            }
        }


        /// <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 = ProxiedView 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 = ProxiedView as IEditableCollectionView;
            if (ecv != null)
            {
                ecv.CancelNew();
            }
            else
            {
                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "CancelNew"));
            }

View on GitHub (pinned to 81131a70a4)