dotnet/wpf · error · InvalidOperationException

throw new…

Error message

throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "NewItemPlaceholderPosition"));

What it means

CollectionViewProxy forwards IEditableCollectionView members to the underlying view; the NewItemPlaceholderPosition setter throws InvalidOperationException(MemberNotAllowedForView) when the proxied view does not implement IEditableCollectionView, so the placeholder position cannot be set.

Solutions

  1. Check whether the view implements IEditableCollectionView before setting NewItemPlaceholderPosition
  2. Ensure the source collection is an editable list (e.g. IList backed ListCollectionView)
  3. Remove or disable placeholder-position UI when the current view is not editable

Example fix

// before
view.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd;
// after
if (view is IEditableCollectionView ecv)
    ecv.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd;
Defensive patterns

Strategy: type-guard

Validate before calling

if (view is IEditableCollectionView ecv) { ecv.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd; }

Type guard

bool SupportsPlaceholder(ICollectionView v) => v is IEditableCollectionView;

Try / catch

try { proxy.NewItemPlaceholderPosition = value; } catch (InvalidOperationException) { /* view not editable; hide placeholder UI */ }

Prevention

When it happens

Trigger: Setting (proxy as ICollectionView).NewItemPlaceholderPosition on a view that isn't editable (e.g. ListCollectionView over non-editable data, or a plain CollectionView).

Common situations: Sharing one proxy/control across different collection views where some support editing; setting placeholder position unconditionally in view initialization code.

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/4f2dba0736dbfee0. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs:407

                if (ecv != null)
                {
                    return ecv.NewItemPlaceholderPosition;
                }
                else
                {
                    return NewItemPlaceholderPosition.None;
                }
            }
            set
            {
                IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;
                if (ecv != null)
                {
                    ecv.NewItemPlaceholderPosition = value;
                }
                else
                {
                    throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, "NewItemPlaceholderPosition"));
                }
            }
        }

        /// <summary>
        /// Return true if the view supports <seealso cref="IEditableCollectionView.AddNew"/>.
        /// </summary>
        bool IEditableCollectionView.CanAddNew
        {
            get
            {
                IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;
                if (ecv != null)
                {
                    return ecv.CanAddNew;
                }
                else
                {

View on GitHub (pinned to 81131a70a4)