dotnet/wpf · error · InvalidOperationException
SR.Format(SR.MemberNotAllowedForView, "AddNew")
Error message
SR.Format(SR.MemberNotAllowedForView, "AddNew")
What it means
BindingListCollectionView.AddNew() throws this InvalidOperationException when the view does not currently permit adding a new item. AddNew first implicitly closes any pending CommitEdit/CommitNew transactions, then checks the CanAddNew flag; if the bound collection is not IBindingList with AllowNew support (or filtering/sorting state makes a new item unplaceable), the operation is rejected.
Solutions
- Check the view's CanAddNew property before calling AddNew and disable/redirect the Add action when false.
- Use a source collection implementing IBindingList with AllowNew == true (e.g. BindingList<T> or a DataView).
- Clear any active EditItem/AddNew transaction first; a pending transaction is implicitly closed, but the view may still report CanAddNew false due to filter state.
- If a filter is active, verify your filter allows the position where the new item would be inserted, or remove the filter before adding.
Example fix
// before
((BindingListCollectionView)view).AddNew();
// after
var blcv = (BindingListCollectionView)view;
if (!blcv.CanAddNew) throw new NotSupportedException("Collection does not allow adding.");
blcv.AddNew(); Defensive patterns
Strategy: validation
Validate before calling
// C#
var blcv = view as BindingListCollectionView;
if (blcv == null || !blcv.CanAddNew) throw new InvalidOperationException("Cannot add new item on this view."); Type guard
bool CanAddSafely(ICollectionView v) => v is BindingListCollectionView b && b.CanAddNew;
Prevention
- Bind to IBindingList sources (BindingList<T>) when you need AddNew.
- Always check CanAddNew before AddNew.
- Close open edit transactions before starting an add.
When it happens
Trigger: Calling AddNew() on a BindingListCollectionView whose source collection is not IBindingList, whose AllowNew property is false, or whose custom CanAddNew logic (e.g. AddNew canPlaceNewItem filter) returns false.
Common situations: Binding an ItemsControl to a plain List<T> or ObservableCollection<T> (not BindingList<T>) and calling AddNew from an 'Add' button; a DataGrid in edit mode issuing implicit AddNew; a filter predicate rejecting the placeholder position for a new item.
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.BindingGroup_CannotChangeGroups
- SR.Format(SR.BindingExpressionStatusChanged, _status…
- SR.Format(SR.MemberNotAllowedDuringAddOrEdit, "Sorting")
- SR.Panel_BoundPanel_NoChildren
- ArgumentNullException(nameof(value))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/2afb6f00c5004198.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs:569
/// <summary>
/// Add a new item to the underlying collection. Returns the new item.
/// After calling AddNew and changing the new item as desired, either
/// <seealso cref="CommitNew"/> or <seealso cref="CancelNew"/> should be
/// called to complete the transaction.
/// </summary>
public object AddNew()
{
VerifyRefreshNotDeferred();
if (IsEditingItem)
{
CommitEdit(); // implicitly close a previous EditItem
}
CommitNew(); // implicitly close a previous AddNew
if (!CanAddNew)
throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "AddNew"));
object newItem = null;
BindingOperations.AccessCollection(InternalList,
() =>
{
ProcessPendingChanges();
_newItemIndex = -2; // this is a signal that the next ItemAdded event comes from AddNew
newItem = InternalList.AddNew();
},
true);
Debug.Assert(_newItemIndex != -2 && newItem == _newItem, "AddNew did not raise expected events");
MoveCurrentTo(newItem);
ISupportInitialize isi = newItem as ISupportInitialize;
isi?.BeginInit();View on GitHub (pinned to 81131a70a4)