{"record":{"id":"2195552fb6b7ab1c","repo":"dotnet/wpf","slug":"sr-format-sr-membernotallowedduringtransaction-219555","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/ListCollectionView.cs","lineNumber":542,"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":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs#L524-L560","documentation":"NewItemPlaceholderPosition cannot be changed while an AddNew transaction is in progress. When the value differs from the current one and IsAddingNew is true, the view throws InvalidOperationException naming AddNew as the blocking transaction.","triggerScenarios":"Setting NewItemPlaceholderPosition (to e.g. First or Last) after calling AddNew() but before CommitNew()/CancelNew(); also deferred via DeferAction if raised during item removal.","commonSituations":"Toggling placeholder placement in UI code (e.g. moving the 'add new' placeholder to the top of a DataGrid) while a new-item row is already active.","solutions":["Commit or cancel the AddNew transaction before changing NewItemPlaceholderPosition","Set NewItemPlaceholderPosition before starting the AddNew transaction","Skip the change when the requested value equals the current value (the throw only occurs when they differ)"],"exampleFix":"// before\ncollectionView.AddNew();\ncollectionView.NewItemPlaceholderPosition = NewItemPlaceholderPosition.First; // throws\n// after\nif (collectionView.IsAddingNew) collectionView.CommitNew();\ncollectionView.NewItemPlaceholderPosition = NewItemPlaceholderPosition.First;","handlingStrategy":"validation","validationCode":"var ecv = collectionView as IEditableCollectionView;\nif (value != collectionView.NewItemPlaceholderPosition &&\n    !(ecv != null && ecv.IsAddingNew))\n{\n    collectionView.NewItemPlaceholderPosition = value;\n}","typeGuard":null,"tryCatchPattern":"try { collectionView.NewItemPlaceholderPosition = value; }\ncatch (InvalidOperationException)\n{\n    // AddNew in progress; retry after CommitNew/CancelNew\n}","preventionTips":["Set NewItemPlaceholderPosition once at view initialization, before any AddNew","Only change placement when its value actually differs (same-value assignments are allowed)","Commit or cancel AddNew before altering placeholder behavior"],"tags":["wpf","data-binding","invalidoperationexception","listcollectionview","placeholder"],"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"}