MahApps/MahApps.Metro · warning · NotSupportedException

Unsupported NotifyCollectionChangedAction

Error message

Unsupported NotifyCollectionChangedAction

What it means

Thrown in the ItemsSource collection-changed handler of MultiSelectionComboBox when a NotifyCollectionChangedAction value is not Add, Remove, Replace, Move, or Reset. The switch handles all five standard enum members; the default is unreachable with standard ObservableCollection but guards against future enum extensions or custom INotifyCollectionChanged implementations.

Source

Thrown at src/MahApps.Metro/Controls/MultiSelectionComboBox/MultiSelectionComboBox.cs:1348

                        {
                            this.PART_PopupListBox?.Items?.Remove(item);
                        }
                    }

                    break;

                case NotifyCollectionChangedAction.Replace:
                case NotifyCollectionChangedAction.Move:
                case NotifyCollectionChangedAction.Reset:
                    this.PART_PopupListBox?.Items.Clear();
                    foreach (var item in this.Items)
                    {
                        this.PART_PopupListBox?.Items?.Add(item);
                    }

                    break;
                default:
                    throw new NotSupportedException("Unsupported NotifyCollectionChangedAction");
            }
        }

        protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        {
            base.OnRenderSizeChanged(sizeInfo);

            // For now we only want to update our position if the height changed. Else we will get a flickering in SharedGridColumns
            if (this.IsDropDownOpen && sizeInfo.HeightChanged)
            {
                this.BeginInvoke(multiSelectionComboBox =>
                    {
                        if (multiSelectionComboBox.PART_Popup is not null)
                        {
                            multiSelectionComboBox.PART_Popup.HorizontalOffset++;
                            multiSelectionComboBox.PART_Popup.HorizontalOffset--;
                        }
                    });

View on GitHub (pinned to 72099e310b)

Solutions

  1. Use ObservableCollection<T> or a collection that only raises standard Add/Remove/Replace/Move/Reset actions.
  2. If implementing a custom INotifyCollectionChanged source, restrict to the five documented actions.
  3. Wrap non-standard collections in an ObservableCollection adapter before binding.
Defensive patterns

Strategy: validation

Validate before calling

void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
    if (!Enum.IsDefined(typeof(NotifyCollectionChangedAction), e.Action))
        throw new ArgumentOutOfRangeException(nameof(e.Action));
    // proceed
}

Type guard

static bool IsStandardAction(NotifyCollectionChangedAction a) =>
    a == NotifyCollectionChangedAction.Add
    || a == NotifyCollectionChangedAction.Remove
    || a == NotifyCollectionChangedAction.Replace
    || a == NotifyCollectionChangedAction.Move
    || a == NotifyCollectionChangedAction.Reset;

Prevention

When it happens

Trigger: A custom collection implementing INotifyCollectionChanged raises CollectionChanged with an action value outside the standard five members (only possible via an untyped/reflective raise). Standard ObservableCollection will never produce this.

Common situations: Custom observable collection or test fixture firing a non-standard action. Not a typical production scenario.

Related errors


AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13). Data as JSON: /api/errors/3d424c2351aaaeef. Report an issue: GitHub.