dotnet/wpf · error · InvalidOperationException
throw new…
Error message
throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "CancelNew"));
What it means
CollectionViewProxy.CancelNew() forwards to the proxied view's IEditableCollectionView.CancelNew. If the proxied view does not implement IEditableCollectionView (null `ecv` at CollectionViewProxy.cs:482), the proxy throws InvalidOperationException because there is no AddNew transaction machinery to cancel.
Solutions
- Guard with CanCancelNew before calling CancelNew
- Ensure the underlying collection's view implements IEditableCollectionView (e.g. use ItemCollection/ListCollectionView-backed sources)
- Add IEditableCollectionView support to a custom ICollectionView implementation
Example fix
// before
proxy.CancelNew();
// after
if (proxy.CanCancelNew)
{
proxy.CancelNew();
} Defensive patterns
Strategy: validation
Validate before calling
if (!proxy.CanCancelNew) return; proxy.CancelNew();
Type guard
bool SupportsCancelNew(CollectionViewProxy p) => p?.ProxiedView is IEditableCollectionView;
Try / catch
try { proxy.CancelNew(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("CancelNew")) { /* nothing to cancel / unsupported view */ } Prevention
- Gate CancelNew behind CanCancelNew checks
- Keep a single code path for add/cancel transactions so unsupported views never reach it
- Test with the actual bound view type, not just ListCollectionView
When it happens
Trigger: Calling CollectionViewProxy.CancelNew() when the wrapped view does not implement IEditableCollectionView, or when no AddNew is possible on that view type.
Common situations: Canceling a 'new item' row in a data-bound grid backed by a collection view without edit support; refactoring code that previously bound to ListCollectionView to a custom view; unit tests invoking CancelNew on stub 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/97a7446728b7f314.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs:482
{
throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "CommitNew"));
}
}
/// <summary>
/// Complete the transaction started by <seealso cref="IEditableCollectionView.AddNew"/>. The new
/// item is removed from the collection.
/// </summary>
void IEditableCollectionView.CancelNew()
{
IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;
if (ecv != null)
{
ecv.CancelNew();
}
else
{
throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "CancelNew"));
}
}
/// <summary>
/// Returns true if an </seealso cref="IEditableCollectionView.AddNew"> transaction is in progress.
/// </summary>
bool IEditableCollectionView.IsAddingNew
{
get
{
IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;
if (ecv != null)
{
return ecv.IsAddingNew;
}
else
{
return false;View on GitHub (pinned to 81131a70a4)