{"record":{"id":"a5a85de33bb5638e","repo":"MahApps/MahApps.Metro","slug":"unknown-selectionmode","errorCode":null,"errorMessage":"Unknown SelectionMode","messagePattern":"Unknown SelectionMode","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"src/MahApps.Metro/Controls/Helper/MahAppsCommands.cs","lineNumber":122,"sourceCode":"                    if (comboBox is MultiSelectionComboBox multiSelectionComboBox)\n                    {\n                        if (multiSelectionComboBox.HasCustomText)\n                        {\n                            multiSelectionComboBox.ResetEditableText(true);\n                        }\n                        else\n                        {\n                            switch (multiSelectionComboBox.SelectionMode)\n                            {\n                                case SelectionMode.Single:\n                                    multiSelectionComboBox.SetCurrentValue(MultiSelectionComboBox.SelectedItemProperty, null);\n                                    break;\n                                case SelectionMode.Multiple:\n                                case SelectionMode.Extended:\n                                    multiSelectionComboBox.SelectedItems?.Clear();\n                                    break;\n                                default:\n                                    throw new NotSupportedException(\"Unknown SelectionMode\");\n                            }\n\n                            multiSelectionComboBox.ResetEditableText(true);\n                        }\n\n                        comboBox.GetBindingExpression(ComboBox.TextProperty)?.UpdateSource();\n                        comboBox.GetBindingExpression(MultiSelectionComboBox.SelectedItemProperty)?.UpdateSource();\n                        comboBox.GetBindingExpression(MultiSelectionComboBox.SelectedItemsProperty)?.UpdateSource();\n                    }\n                    else\n                    {\n                        if (comboBox.IsEditable)\n                        {\n                            comboBox.SetCurrentValue(ComboBox.TextProperty, string.Empty);\n                            comboBox.GetBindingExpression(ComboBox.TextProperty)?.UpdateSource();\n                        }\n\n                        comboBox.SetCurrentValue(Selector.SelectedItemProperty, null);","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/Helper/MahAppsCommands.cs#L104-L140","documentation":"Thrown by the MahApps clear-text command when a MultiSelectionComboBox.SelectionMode value is not Single, Multiple, or Extended. The switch exhausts the standard System.Windows.Controls.SelectionMode enum; the default branch is a defensive guard against an unexpected/extended enum value. In normal usage this is unreachable because SelectionMode only has those three members.","triggerScenarios":"Calling the MahApps 'Clear' textbox command (e.g. clear-text button) on a MultiSelectionComboBox whose SelectionMode was set to a non-standard enum value via reflection or a future framework enum extension; a custom derivative overriding SelectionMode semantics.","commonSituations":"Effectively unreachable with the current WPF SelectionMode enum; would surface if a fork adds a new SelectionMode member without updating this switch, or if an invalid integer is cast into SelectionMode.","solutions":["Use only the standard SelectionMode values (Single, Multiple, Extended) on MultiSelectionComboBox.","If extending SelectionMode, patch this switch to handle the new case.","Report the unexpected value to MahApps if a stock enum legitimately produces it.","Avoid casting arbitrary integers into SelectionMode."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// SelectionMode is a closed enum (Single, Multiple, Extended). Validate before relying on it.\nif (multiSelectionComboBox.SelectionMode is not (SelectionMode.Single or SelectionMode.Multiple or SelectionMode.Extended))\n{\n    throw new ArgumentOutOfRangeException(nameof(multiSelectionComboBox.SelectionMode));\n}","typeGuard":"static bool IsKnownMode(SelectionMode m)\n    => m == SelectionMode.Single || m == SelectionMode.Multiple || m == SelectionMode.Extended;","tryCatchPattern":"try { /* invoke clear command */ }\ncatch (NotSupportedException ex) when (ex.Message == \"Unknown SelectionMode\")\n{\n    // A future/invalid SelectionMode value; reset to a known mode.\n    multiSelectionComboBox.SelectionMode = SelectionMode.Single;\n}","preventionTips":["Only set SelectionMode to Single, Multiple, or Extended.","Never cast arbitrary integers into SelectionMode.","If extending the enum, patch the MahApps switch to cover the new member."],"tags":["wpf","multiselection-combobox","mahapps","enum","defensive"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}