MahApps/MahApps.Metro · warning · NotSupportedException
Unknown SelectionMode
Error message
Unknown SelectionMode
What it means
Thrown by MultiSelectionComboBox when the ItemsSource/text-clearing logic encounters a SelectionMode value that is not Single, Multiple, or Extended. The switch's default branch fires because the enum value is outside the supported set. In practice System.Windows.Controls.SelectionMode only has those three values, so this is a defensive guard against future enum additions or reflected/constructed values.
Source
Thrown at src/MahApps.Metro/Controls/MultiSelectionComboBox/MultiSelectionComboBox.cs:913
private void UpdateSelectedItemsFromTextTimer_Tick(object sender, EventArgs e)
#endif
{
this.updateSelectedItemsFromTextTimer?.Stop();
// We clear the selection if there is no text available.
if (string.IsNullOrEmpty(this.Text))
{
switch (this.SelectionMode)
{
case SelectionMode.Single:
this.SetCurrentValue(SelectedItemProperty, null);
break;
case SelectionMode.Multiple:
case SelectionMode.Extended:
this.SelectedItems?.Clear();
break;
default:
throw new NotSupportedException("Unknown SelectionMode");
}
return;
}
bool foundItem;
switch (this.SelectionMode)
{
case SelectionMode.Single:
this.SetCurrentValue(SelectedItemProperty, null);
foundItem = false;
if (this.ObjectToStringComparer is not null)
{
foreach (var item in this.Items)
{
if (this.ObjectToStringComparer.CheckIfStringMatchesObject(this.Text, item, this.EditableTextStringComparision, this.SelectedItemStringFormat))View on GitHub (pinned to 72099e310b)
Solutions
- Ensure SelectionMode is only set to SelectionMode.Single, SelectionMode.Multiple, or SelectionMode.Extended.
- If setting the property via binding or serialization, validate the value is within the supported set before assignment.
- Do not use reflection to inject arbitrary enum values into the SelectionMode property.
Example fix
// before
combo.SetCurrentValue(SelectionModeProperty, (SelectionMode)99);
// after
if (mode == SelectionMode.Single || mode == SelectionMode.Multiple || mode == SelectionMode.Extended)
{
combo.SetCurrentValue(SelectionModeProperty, mode);
} Defensive patterns
Strategy: validation
Validate before calling
var validModes = new[] { SelectionMode.Single, SelectionMode.Multiple, SelectionMode.Extended };
if (!validModes.Contains(mode))
throw new ArgumentOutOfRangeException(nameof(mode));
combo.SelectionMode = mode; Type guard
static bool IsValidSelectionMode(SelectionMode m) =>
m == SelectionMode.Single || m == SelectionMode.Multiple || m == SelectionMode.Extended; Prevention
- Only assign the three documented SelectionMode values.
- Do not inject enum values via reflection.
- Validate bound SelectionMode sources before assignment.
When it happens
Trigger: The control's SelectionMode property is set to an enum value other than Single/Multiple/Extended (only possible via reflection or a future framework change), then the text is cleared (string.IsNullOrEmpty(Text) is true), triggering the clearing switch with the unhandled case.
Common situations: Very unlikely in normal usage. Could surface in unit tests or serialization scenarios that inject an invalid SelectionMode via reflection. Not a typical production runtime error.
Related errors
- Unsupported NotifyCollectionChangedAction
- Template part "{templatePart}" in template for "{target.GetT
- The provided dialog is already visible in the specified wind
- The provided dialog is not visible in the specified window.
- Dialog isn't visible to close
AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13).
Data as JSON: /api/errors/5d593ba0d834c7e0.
Report an issue: GitHub.