dotnet/wpf · error · InvalidOperationException
SR.Format(SR.MemberNotAllowedForView, "EditItem")
Error message
SR.Format(SR.MemberNotAllowedForView, "EditItem")
What it means
ItemCollection.EditItem throws InvalidOperationException(SR.MemberNotAllowedForView, "EditItem") when the underlying view does not implement IEditableCollectionView, so transactional editing of an item is unavailable. The wrapper forwards only to editing-capable views.
Solutions
- Bind ItemsSource to a collection whose default view implements IEditableCollectionView.
- Guard with `items.CanEditItem` (or check the view) before starting an edit transaction.
- Mutate the item's properties directly and rely on INotifyPropertyChanged instead of view-based edit transactions.
Example fix
// before
items.EditItem(selectedItem);
// after
if (items.CanEditItem)
items.EditItem(selectedItem);
else
throw new InvalidOperationException("View does not support EditItem"); Defensive patterns
Strategy: validation
Validate before calling
if (items.CanEditItem)
items.EditItem(item); Type guard
static bool CanEdit(ItemCollection c) => c.CollectionView is IEditableCollectionView;
Try / catch
try { items.EditItem(item); }
catch (InvalidOperationException) { /* edit transactions unsupported; mutate item directly */ } Prevention
- Check CanEditItem before EditItem
- Ensure the ItemsSource view implements IEditableCollectionView in editable grids (DataGrid)
- Complete or cancel any open edit transaction before rebinding ItemsSource
When it happens
Trigger: Calling items.EditItem(item) when ItemsSource's view is not an IEditableCollectionView.
Common situations: Editable DataGrid scenarios where the ItemsSource is a plain collection without an editable view; rebinding ItemsSource to a type whose default view lacks IEditableCollectionView while editing logic still runs.
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…
- SR.Format(SR.MemberNotAllowedForView, "AddNew")
- SR.Format(SR.MemberNotAllowedForView, "CancelNew")
- SR.Format(SR.MemberNotAllowedForView, "CommitNew")
- SR.Format(SR.MemberNotAllowedForView, "Remove")
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/b02cf787f1d3c42d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs:1083
#region Transactional editing of an item
/// <summary>
/// Begins an editing transaction on the given item. The transaction is
/// completed by calling either <seealso cref="IEditableCollectionView.CommitEdit"/> or
/// <seealso cref="IEditableCollectionView.CancelEdit"/>. Any changes made to the item during
/// the transaction are considered "pending", provided that the view supports
/// the notion of "pending changes" for the given item.
/// </summary>
void IEditableCollectionView.EditItem(object item)
{
IEditableCollectionView ecv = _collectionView as IEditableCollectionView;
if (ecv != null)
{
ecv.EditItem(item);
}
else
{
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 = _collectionView as IEditableCollectionView;
if (ecv != null)
{
ecv.CommitEdit();
}
else
{
throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "CommitEdit"));
}View on GitHub (pinned to 81131a70a4)