dotnet/wpf · error · InvalidOperationException
throw new…
Error message
throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "CancelEdit"));
What it means
CollectionViewProxy.CancelEdit() discards pending item changes by delegating to IEditableCollectionView.CancelEdit on the proxied view. When the wrapped view does not implement that interface (null `ecv` at CollectionViewProxy.cs:637), the proxy throws InvalidOperationException because this view does not support canceling edits.
Solutions
- Check CanCancelEdit before calling CancelEdit
- Back the view with a collection whose view implements IEditableCollectionView
- Implement IEditableCollectionView on custom views that need edit transactions
Example fix
// before
proxy.CancelEdit();
// after
if (proxy.CanCancelEdit)
{
proxy.CancelEdit();
} Defensive patterns
Strategy: validation
Validate before calling
if (!proxy.CanCancelEdit) return; proxy.CancelEdit();
Type guard
bool SupportsCancelEdit(CollectionViewProxy p) => p?.ProxiedView is IEditableCollectionView;
Try / catch
try { proxy.CancelEdit(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("CancelEdit")) { /* unsupported view; discard changes manually */ } Prevention
- Check CanCancelEdit before canceling
- Keep snapshots of edited objects as a manual rollback fallback
- Use ObservableCollection<T>/ListCollectionView when edit transactions are needed
When it happens
Trigger: Calling CancelEdit on a CollectionViewProxy whose ProxiedView is not IEditableCollectionView.
Common situations: Escaping row edits in a data-bound grid backed by an unsupported collection; view-models that always call CancelEdit in error handlers; switching collection implementations without updating view code.
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/e8ea941d08885afd.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs:637
{
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"));
}
}
/// <summary>
/// Returns true if the view supports the notion of "pending changes" on the
/// current edit item. This may vary, depending on the view and the particular
/// item. For example, a view might return true if the current edit item
/// implements <seealso cref="IEditableObject"/>, or if the view has special
/// knowledge about the item that it can use to support rollback of pending
/// changes.
/// </summary>
bool IEditableCollectionView.CanCancelEdit
{
get
{
IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;
if (ecv != null)
{View on GitHub (pinned to 81131a70a4)