{"record":{"id":"de245dc7f173c479","repo":"dotnet/wpf","slug":"sr-format-sr-membernotallowedduringtransaction","errorCode":null,"errorMessage":"SR.Format(SR.MemberNotAllowedDuringTransaction, \"NewItemPlaceholderPosition\", \"AddNew\")","messagePattern":"SR\\.Format\\(SR\\.MemberNotAllowedDuringTransaction, \"NewItemPlaceholderPosition\", \"AddNew\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs","lineNumber":429,"sourceCode":"        #endregion Public Properties\n\n        #region IEditableCollectionView\n\n        #region Adding new items\n\n        /// <summary>\n        /// Indicates whether to include a placeholder for a new item, and if so,\n        /// where to put it.\n        /// </summary>\n        public NewItemPlaceholderPosition NewItemPlaceholderPosition\n        {\n            get { return _newItemPlaceholderPosition; }\n            set\n            {\n                VerifyRefreshNotDeferred();\n\n                if (value != _newItemPlaceholderPosition && IsAddingNew)\n                    throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedDuringTransaction, \"NewItemPlaceholderPosition\", \"AddNew\"));\n\n                if (value != _newItemPlaceholderPosition && _isRemoving)\n                {\n                    DeferAction(() => { NewItemPlaceholderPosition = value; });\n                    return;\n                }\n\n                NotifyCollectionChangedEventArgs args = null;\n                int oldIndex=-1, newIndex=-1;\n\n                // we're adding, removing, or moving the placeholder.\n                // Determine the appropriate events.\n                switch (value)\n                {\n                    case NewItemPlaceholderPosition.None:\n                        switch (_newItemPlaceholderPosition)\n                        {\n                            case NewItemPlaceholderPosition.None:","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs#L411-L447","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["End the AddNew transaction first: call CommitNew() (or CancelNew()) before changing NewItemPlaceholderPosition.","Check IsAddingNew before assigning and defer the change until the transaction completes.","If the same value is being re-assigned, guard with a check so no-op assignments don't run during the transaction."],"exampleFix":"// before\nview.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtBeginning; // throws during AddNew\n\n// after\nif (view.IsAddingNew) view.CommitNew();\nview.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtBeginning;","handlingStrategy":"validation","validationCode":"if (view.IsAddingNew) view.CommitNew();\nif (view.NewItemPlaceholderPosition != desiredPosition)\n    view.NewItemPlaceholderPosition = desiredPosition;","typeGuard":null,"tryCatchPattern":"try { view.NewItemPlaceholderPosition = pos; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"NewItemPlaceholderPosition\"))\n{\n    // defer until AddNew completes\n}","preventionTips":["Commit or cancel AddNew before moving the placeholder","Skip no-op assignments when the position is unchanged","Configure placeholder position at view creation, not during add flows"],"tags":["wpf","collection-view","placeholder","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}