{"record":{"id":"4430ff936c47beeb","repo":"dotnet/wpf","slug":"sr-uia-operationcannotbeperformed-radiobuttonautomationpeer","errorCode":null,"errorMessage":"SR.UIA_OperationCannotBePerformed","messagePattern":"SR\\.UIA_OperationCannotBePerformed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/RadioButtonAutomationPeer.cs","lineNumber":64,"sourceCode":"        /// Sets the current element as the selection\n        /// This clears the selection from other elements in the container\n        /// </summary>\n        void ISelectionItemProvider.Select()\n        {\n            if (!IsEnabled())\n                throw new ElementNotEnabledException();\n\n            ((RadioButton)Owner).SetCurrentValueInternal(RadioButton.IsCheckedProperty, MS.Internal.KnownBoxes.BooleanBoxes.TrueBox);\n        }\n\n\n        /// <summary>\n        /// Adds current element to selection\n        /// </summary>\n        void ISelectionItemProvider.AddToSelection()\n        {\n            if (((RadioButton)Owner).IsChecked != true)\n                throw new InvalidOperationException(SR.UIA_OperationCannotBePerformed);\n        }\n\n\n        /// <summary>\n        /// Removes current element from selection\n        /// </summary>\n        void ISelectionItemProvider.RemoveFromSelection()\n        {\n            // If RadioButton is checked - RemoveFromSelection is invalid operation\n            if (((RadioButton)Owner).IsChecked == true)\n                throw new InvalidOperationException(SR.UIA_OperationCannotBePerformed);\n        }\n\n\n        /// <summary>\n        /// Check whether an element is selected\n        /// </summary>\n        /// <value>returns true if the element is selected</value>","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/RadioButtonAutomationPeer.cs#L46-L82","documentation":"ISelectionItemProvider.AddToSelection() on RadioButtonAutomationPeer throws InvalidOperationException with SR.UIA_OperationCannotBePerformed when the RadioButton is not already checked (IsChecked != true). Radio buttons are single-select: they can never be 'added' to a selection alongside another element, so AddToSelection is only a no-op success for an already-selected radio and an error otherwise.","triggerScenarios":"A UIA client calls SelectionItemPattern.AddToSelection() on an unchecked RadioButton; generic pattern-exercising harnesses that call AddToSelection on every SelectionItem-capable element.","commonSituations":"Test frameworks generated from pattern lists rather than control semantics; migration of automation written for list items (where AddToSelection is valid) applied to radio button groups.","solutions":["Use SelectionItemPattern.Select() (or set IsChecked=true) instead of AddToSelection for radio buttons.","Skip AddToSelection for elements whose SelectionItem pattern reports IsSelectionRequired / single-select semantics like radios.","Catch InvalidOperationException and translate it to a Select() call in generic harnesses."],"exampleFix":"// before\nselectionItemPattern.AddToSelection(); // radio buttons: not supported\n// after\nif (((RadioButton)owner).IsChecked != true)\n{\n    selectionItemPattern.Select(); // correct single-select operation\n}","handlingStrategy":"validation","validationCode":"if (element is radio button or single-select) use Select(); // only use AddToSelection for multi-select containers","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call AddToSelection on radio buttons; always use Select","Generate automation from control semantics, not just supported pattern lists","Audit harnesses that blanket-call all SelectionItem methods"],"tags":["wpf","uiautomation","radiobutton","selection","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-21T21:30:21.729Z"}