dotnet/wpf · error · InvalidOperationException

throw new…

Error message

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

What it means

CollectionViewProxy.CommitEdit() completes a pending edit transaction by delegating to the proxied view's IEditableCollectionView.CommitEdit. If the wrapped view lacks that interface (null `ecv` at CollectionViewProxy.cs:620), the proxy throws InvalidOperationException since there is no edit transaction support.

Solutions

  1. Guard with CanCommitEdit before calling CommitEdit
  2. Ensure the view is an IEditableCollectionView (e.g. bind to ObservableCollection<T> viewed through ListCollectionView)
  3. Implement IEditableCollectionView in custom view classes

Example fix

// before
proxy.CommitEdit();
// after
if (proxy.CanCommitEdit)
{
    proxy.CommitEdit();
}
Defensive patterns

Strategy: validation

Validate before calling

if (!proxy.CanCommitEdit) return;
proxy.CommitEdit();

Type guard

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

Try / catch

try { proxy.CommitEdit(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("CommitEdit")) { /* unsupported view; commit via object model */ }

Prevention

When it happens

Trigger: Calling CommitEdit on a CollectionViewProxy wrapping a non-IEditableCollectionView view, including cases where no edit is in progress on an unsupported view.

Common situations: Committing grid edits on DataBinding over read-only or custom collections; code paths shared between editable and non-editable views; automated UI tests calling CommitEdit unconditionally.

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/712274298e1aefd6. Report an issue: GitHub.

Appendix: source

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

            {
                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "EditItem"));
            }
        }

        /// <summary>
        /// Complete the transaction started by <seealso cref="IEditableCollectionView.EditItem"/>.
        /// The pending changes (if any) to the item are committed.
        /// </summary>
        void IEditableCollectionView.CommitEdit()
        {
            IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;
            if (ecv != null)
            {
                ecv.CommitEdit();
            }
            else
            {
                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "CommitEdit"));
            }
        }

        /// <summary>
        /// Complete the transaction started by <seealso cref="IEditableCollectionView.EditItem"/>.
        /// The pending changes (if any) to the item are discarded.
        /// </summary>
        void IEditableCollectionView.CancelEdit()
        {
            IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;
            if (ecv != null)
            {
                ecv.CancelEdit();
            }
            else
            {
                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "CancelEdit"));
            }

View on GitHub (pinned to 81131a70a4)