{"record":{"id":"7884b9c1749b1cf3","repo":"dotnet/wpf","slug":"sr-doesnotsupportmultipleselection-windowsmenu","errorCode":null,"errorMessage":"SR.DoesNotSupportMultipleSelection","messagePattern":"SR\\.DoesNotSupportMultipleSelection","errorType":"exception","errorClass":"System.InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsMenu.cs","lineNumber":1799,"sourceCode":"            // Selects this element\n            void ISelectionItemProvider.Select()\n            {\n                // Make sure that the control is enabled\n                if (!IsEnabledMenu)\n                {\n                    throw new ElementNotEnabledException();\n                }\n\n                SetFocus();\n\n                // sending enter key to the currently selected item\n                ExpandViaEnter();\n            }\n\n            // Adds this element to the selection\n            void ISelectionItemProvider.AddToSelection()\n            {\n                throw new InvalidOperationException(SR.DoesNotSupportMultipleSelection);\n            }\n\n            // Removes this element from the selection\n            void ISelectionItemProvider.RemoveFromSelection()\n            {\n                throw new InvalidOperationException(SR.DoesNotSupportMultipleSelection);\n            }\n\n            // True if this element is part of the the selection\n            bool ISelectionItemProvider.IsSelected\n            {\n                get\n                {\n                    return IsChecked() ? true : false;\n                }\n            }\n\n            // Returns the container for this element","sourceCodeStart":1781,"sourceCodeEnd":1817,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsMenu.cs#L1781-L1817","documentation":"WindowsMenu's ISelectionItemProvider.AddToSelection deliberately throws InvalidOperationException with SR.DoesNotSupportMultipleSelection. Win32 menus only support a single selected item, so multi-select semantics are not available on menu item proxies. The provider implements ISelectionItemProvider for selection reporting, but refuses the multi-select-style add operation.","triggerScenarios":"Calling UIA's SelectionItemPattern.AddToSelection() on a Win32 menu item proxy (WindowsMenu item) retrieved from a classic Win32 menu (Menu bar, submenu, context menu).","commonSituations":"Automation scripts written generically against SelectionItemPattern that call AddToSelection on every element supporting the pattern; test frameworks ported from list-view/tree automation to menu automation; list boxes with multi-selection semantics being driven through menu-item code paths.","solutions":["Use SelectionItemPattern.Select() instead of AddToSelection() to select the menu item.","Check the container's SelectionPattern.CanSelectMultiple property before calling AddToSelection; only call it when multiple selection is supported.","If the goal is to open a menu, use InvokePattern.Invoke() or send the underlying keyboard/mouse gesture instead of selection APIs."],"exampleFix":"// before\nvar selectionItem = menuItem.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;\nselectionItem.AddToSelection();\n\n// after\nvar selectionItem = menuItem.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;\nselectionItem.Select(); // menus support single selection only","handlingStrategy":"validation","validationCode":"var container = menuItem.FindFirst(TreeScope.Ancestors,\n    new PropertyCondition(AutomationElement.IsSelectionPatternAvailableProperty, true));\nbool multi = container?.GetCurrentPattern(SelectionPattern.Pattern) is SelectionPattern sp && sp.Current.CanSelectMultiple;\nif (!multi) itemPattern.Select(); // never AddToSelection on menus","typeGuard":"static bool SupportsMultiSelect(AutomationElement el)\n{\n    return el.FindFirst(TreeScope.Ancestors,\n        new PropertyCondition(AutomationElement.IsSelectionPatternAvailableProperty, true))\n        ?.GetCurrentPattern(SelectionPattern.Pattern) is SelectionPattern sp && sp.Current.CanSelectMultiple;\n}","tryCatchPattern":"try { itemPattern.AddToSelection(); }\ncatch (InvalidOperationException) { itemPattern.Select(); }","preventionTips":["Use Select() for menu items; reserve Add/RemoveFromSelection for multi-select lists","Check SelectionPattern.CanSelectMultiple before add/remove calls","Read IsSelectionPatternAvailable and container capabilities before scripting generic selection logic"],"tags":["ui-automation","menu","selection-pattern","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}