dotnet/wpf · error · InvalidOperationException
SR.Format(SR.MemberNotAllowedDuringAddOrEdit…
Error message
SR.Format(SR.MemberNotAllowedDuringAddOrEdit, "GroupBySelector")
What it means
The GroupBySelector setter throws InvalidOperationException when the view is inside an AddNew or EditItem transaction. Changing grouping (like filtering) during an uncommitted add/edit transaction is rejected with MemberNotAllowedDuringAddOrEdit naming 'GroupBySelector'.
Solutions
- Commit/cancel pending transactions first: CommitNew()/CancelNew() and CommitEdit()/CancelEdit() before setting GroupBySelector.
- Guard the assignment with checks on IsAddingNew/IsEditingItem and defer until the transaction ends.
- Configure grouping once when the view is created, before any user-driven add/edit activity.
Example fix
// before view.GroupBySelector = mySelector; // throws during edit // after if (view.IsAddingNew) view.CommitNew(); if (view.IsEditingItem) view.CommitEdit(); view.GroupBySelector = mySelector;
Defensive patterns
Strategy: validation
Validate before calling
if (view.IsAddingNew) view.CommitNew(); if (view.IsEditingItem) view.CommitEdit(); view.GroupBySelector = selector;
Try / catch
try { view.GroupBySelector = selector; }
catch (InvalidOperationException ex) when (ex.Message.Contains("GroupBySelector"))
{
// retry after committing pending transactions
} Prevention
- End add/edit transactions before regrouping
- Guard grouping changes with IsAddingNew/IsEditingItem checks
- Apply grouping configuration outside row-editing flows
When it happens
Trigger: Assigning BindingListCollectionView.GroupBySelector while IsAddingNew or IsEditingItem is true — e.g. regrouping from a UI command while a DataGrid row is in add/edit mode.
Common situations: Dynamic grouping UI (combo box choosing group property) triggered while a row is being edited; automated tests that change grouping without committing pending transactions; refresh logic that reconfigures grouping on selection-changed events.
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
- SR.Format(SR.MemberNotAllowedDuringAddOrEdit…
- SR.Format(SR.MemberNotAllowedDuringAddOrEdit, "Grouping")
- SR.Format(SR.MemberNotAllowedDuringTransaction…
- ArgumentOutOfRangeException
- Current DocumentSequence, FixedDocument, or FixedPage not…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/29c6febd9d67dd9e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs:369
get { return (_isGrouping) ? _group.Items : null; }
}
#endregion ICollectionView
/// <summary>
/// A delegate to select the group description as a function of the
/// parent group and its level.
/// </summary>
[DefaultValue(null)]
public GroupDescriptionSelectorCallback GroupBySelector
{
get { return _group.GroupBySelector; }
set
{
if (!CanGroup)
throw new NotSupportedException();
if (IsAddingNew || IsEditingItem)
throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedDuringAddOrEdit, "GroupBySelector"));
_group.GroupBySelector = value;
RefreshOrDefer();
}
}
/// <summary>
/// Return the estimated number of records (or -1, meaning "don't know").
/// </summary>
public override int Count
{
get
{
VerifyRefreshNotDeferred();
return InternalCount;
}View on GitHub (pinned to 81131a70a4)