dotnet/wpf · error · InvalidOperationException
throw new…
Error message
throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "RemoveAt"));
What it means
CollectionViewProxy.RemoveAt(index) requires the proxied view to implement IEditableCollectionView, which owns removal-by-index. When the wrapped view lacks that interface (null `ecv` at CollectionViewProxy.cs:563), the proxy throws InvalidOperationException indicating RemoveAt is not allowed for this view.
Solutions
- Check the view supports removal (cast ProxiedView as IEditableCollectionView != null) before RemoveAt
- Remove the item from the underlying collection instead of the view, then let change notifications update the view
- Switch the source collection to a mutable type whose view supports IEditableCollectionView
Example fix
// before
proxy.RemoveAt(0);
// after
var ecv = proxy.ProxiedView as IEditableCollectionView;
if (ecv != null)
{
proxy.RemoveAt(0);
} Defensive patterns
Strategy: validation
Validate before calling
if (proxy.ProxiedView is IEditableCollectionView) { proxy.RemoveAt(index); } Type guard
bool SupportsRemoveAt(CollectionViewProxy p) => p?.ProxiedView is IEditableCollectionView;
Try / catch
try { proxy.RemoveAt(index); }
catch (InvalidOperationException ex) when (ex.Message.Contains("RemoveAt")) { /* fall back to removing from the source collection */ } Prevention
- Remove items from the underlying collection and let change notifications update the view
- Check CanRemove before index-based removal
- Avoid binding editable UI to read-only or immutable source collections
When it happens
Trigger: Calling RemoveAt on a CollectionViewProxy whose ProxiedView implements neither IEditableCollectionView nor an equivalent removal path (the `ecv` cast fails).
Common situations: Removing items from a read-only or fixed-size collection's view; views over arrays or immutable collections; data-binding controls that assume editable views.
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/0bbc65486303b7e6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs:563
}
}
}
/// <summary>
/// Remove the item at the given index from the underlying collection.
/// The index is interpreted with respect to the view (not with respect to
/// the underlying collection).
/// </summary>
void IEditableCollectionView.RemoveAt(int index)
{
IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;
if (ecv != null)
{
ecv.RemoveAt(index);
}
else
{
throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "RemoveAt"));
}
}
/// <summary>
/// Remove the given item from the underlying collection.
/// </summary>
void IEditableCollectionView.Remove(object item)
{
IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;
if (ecv != null)
{
ecv.Remove(item);
}
else
{
throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "Remove"));
}
}View on GitHub (pinned to 81131a70a4)