dotnet/wpf · error · InvalidOperationException

SR.Format(SR.MemberNotAllowedDuringTransaction…

Error message

SR.Format(SR.MemberNotAllowedDuringTransaction, "NewItemPlaceholderPosition", "AddNew")

What it means

The NewItemPlaceholderPosition setter throws InvalidOperationException when the position is being changed while an AddNew transaction is in progress (value differs from the current one and IsAddingNew is true). WPF phrases it via MemberNotAllowedDuringTransaction, naming 'NewItemPlaceholderPosition' and 'AddNew' — the placeholder position cannot move while a new item is being added.

Solutions

  1. End the AddNew transaction first: call CommitNew() (or CancelNew()) before changing NewItemPlaceholderPosition.
  2. Check IsAddingNew before assigning and defer the change until the transaction completes.
  3. If the same value is being re-assigned, guard with a check so no-op assignments don't run during the transaction.

Example fix

// before
view.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtBeginning; // throws during AddNew

// after
if (view.IsAddingNew) view.CommitNew();
view.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtBeginning;
Defensive patterns

Strategy: validation

Validate before calling

if (view.IsAddingNew) view.CommitNew();
if (view.NewItemPlaceholderPosition != desiredPosition)
    view.NewItemPlaceholderPosition = desiredPosition;

Try / catch

try { view.NewItemPlaceholderPosition = pos; }
catch (InvalidOperationException ex) when (ex.Message.Contains("NewItemPlaceholderPosition"))
{
    // defer until AddNew completes
}

Prevention

When it happens

Trigger: Setting BindingListCollectionView.NewItemPlaceholderPosition to a different value while CollectionView.AddNew is outstanding (uncommitted new item). Note: re-setting the same value is allowed; only an actual change during AddNew throws.

Common situations: UI code that toggles placeholder placement (e.g. moving it from Bottom to Top) in response to a command while the DataGrid has a pending new-item row; tests or automation that reconfigure placeholder position without ending AddNew.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/de245dc7f173c479. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs:429

        #endregion Public Properties

        #region IEditableCollectionView

        #region Adding new items

        /// <summary>
        /// Indicates whether to include a placeholder for a new item, and if so,
        /// where to put it.
        /// </summary>
        public NewItemPlaceholderPosition NewItemPlaceholderPosition
        {
            get { return _newItemPlaceholderPosition; }
            set
            {
                VerifyRefreshNotDeferred();

                if (value != _newItemPlaceholderPosition && IsAddingNew)
                    throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedDuringTransaction, "NewItemPlaceholderPosition", "AddNew"));

                if (value != _newItemPlaceholderPosition && _isRemoving)
                {
                    DeferAction(() => { NewItemPlaceholderPosition = value; });
                    return;
                }

                NotifyCollectionChangedEventArgs args = null;
                int oldIndex=-1, newIndex=-1;

                // we're adding, removing, or moving the placeholder.
                // Determine the appropriate events.
                switch (value)
                {
                    case NewItemPlaceholderPosition.None:
                        switch (_newItemPlaceholderPosition)
                        {
                            case NewItemPlaceholderPosition.None:

View on GitHub (pinned to 81131a70a4)