dotnet/wpf · error · InvalidOperationException
SR.Format(SR.MemberNotAllowedForView, "CancelEdit")
Error message
SR.Format(SR.MemberNotAllowedForView, "CancelEdit")
What it means
ItemCollection.CancelEdit discards pending changes to the current edit item, but requires the active view to implement IEditableCollectionView. If the view does not (CanCancelEdit is false), the method throws InvalidOperationException with MemberNotAllowedForView("CancelEdit").
Solutions
- Guard with the CanCancelEdit property before calling CancelEdit
- Cast the view to IEditableCollectionView and check CanCancelEdit before use
- Use an ItemsSource whose view supports edit transactions (e.g. ObservableCollection via ListCollectionView)
Example fix
// before
items.CancelEdit();
// after
if (items.CanCancelEdit) { items.CancelEdit(); } Defensive patterns
Strategy: validation
Validate before calling
if (items.CanCancelEdit) items.CancelEdit();
Type guard
bool canCancel = items.CollectionView is IEditableCollectionView ecv && ecv.CanCancelEdit;
Try / catch
try { items.CancelEdit(); } catch (InvalidOperationException ex) { /* no editable view */ } Prevention
- Check CanCancelEdit before canceling
- Bind to editable sources (ObservableCollection/IBindingList)
- Write cancel logic against IEditableCollectionView explicitly
When it happens
Trigger: Calling ItemCollection.CancelEdit() while the underlying view does not implement IEditableCollectionView, e.g. a view over a read-only or plain IList source.
Common situations: Writing generic undo/cancel logic around ItemsControl edits without first checking CanCancelEdit; using custom CollectionView implementations that omit edit support.
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
- SR.Format(SR.MemberNotAllowedForView, "CommitEdit")
- SR.BadTargetArray
- SR.CannotUseItemsSource
- SR.Format(SR.MemberNotAllowedForView…
- SR.Format(SR.MemberNotAllowedForView, "AddNew")
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/5dd54b7e64382088.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs:1117
{
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 = _collectionView 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 = _collectionView as IEditableCollectionView;
if (ecv != null)
{View on GitHub (pinned to 81131a70a4)