{"record":{"id":"7d421ec2afd72668","repo":"dotnet/wpf","slug":"operation-cannot-be-performed","errorCode":null,"errorMessage":"Operation cannot be performed.","messagePattern":"Operation cannot be performed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsComboBox.cs","lineNumber":394,"sourceCode":"\n                // try to set user-provided text\n                valueProvider.SetValue (str);\n\n                // Let the parent know that the value has change, to allow the parent to do any processing it needs\n                // to do on value change.\n                IntPtr hwndParent = Misc.GetParent(_hwnd);\n                if (hwndParent != IntPtr.Zero)\n                {\n                    int id = Misc.GetWindowId(_hwnd);\n                    IntPtr wParam = new IntPtr(NativeMethods.Util.MAKELONG(id, NativeMethods.CBN_EDITUPDATE));\n\n                    Misc.ProxySendMessage(hwndParent, NativeMethods.WM_COMMAND, wParam, _hwnd);\n                }\n\n                return;\n            }\n\n            throw new InvalidOperationException(SR.OperationCannotBePerformed);\n        }\n\n        // Request to get the value that this UI element is representing as a string\n        string IValueProvider.Value\n        {\n            get\n            {\n                return Text;\n            }\n        }\n\n        bool IValueProvider.IsReadOnly\n        {\n            get\n            {\n                if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n                {\n                    return true;","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsComboBox.cs#L376-L412","documentation":"UIA client-side proxy for Win32 combo boxes throws InvalidOperationException(OperationCannotBePerformed) from IValueProvider.SetValue when the requested value cannot be applied to the native combobox. The proxy sends WM_COMMAND/selection messages to the underlying HWND, and if it cannot select the requested item (e.g. the text does not match any item), it gives up with this error.","triggerScenarios":"Calling IValueProvider.SetValue on a Win32 ComboBox via UI Automation with a value that does not correspond to any item in the combo box's list, or on a combo box whose style prevents programmatic selection (e.g. simple/drop-list combos that cannot accept arbitrary text).","commonSituations":"Test automation scripts selecting a dropdown option by text that has a different casing or trailing whitespace than the actual item; automating read-only drop-list combo boxes as if they were editable; localized applications where item text differs from what the script passes.","solutions":["Pass exactly the text of an existing item in the combo box list (match casing and spacing).","Use SelectionItemPattern.Select() on a child item of the combo box instead of ValuePattern.SetValue.","If arbitrary text is required, use an editable (CBS_DROPDOWN / CBS_SIMPLE) combo box rather than a drop-list.","Catch InvalidOperationException and fall back to keyboard automation (focus + send keys)."],"exampleFix":"// before\nvar valuePattern = comboBox.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;\nvaluePattern.SetValue(\"Item 1\"); // fails if item is actually 'item 1'\n// after\nvar exactItem = comboBox.FindFirst(TreeScope.Children,\n    new PropertyCondition(AutomationElement.NameProperty, \"item 1\"));\n((SelectionItemPattern)exactItem.GetCurrentPattern(SelectionItemPattern.Pattern)).Select();","handlingStrategy":"validation","validationCode":"var vp = (ValuePattern)el.GetCurrentPattern(ValuePattern.Pattern);\nstring existing = vp.Current.Value;\nbool known = string.Equals(existing, desired, StringComparison.Ordinal);\n// also confirm a matching child item exists for drop-list combos","typeGuard":null,"tryCatchPattern":"try { vp.SetValue(desired); }\ncatch (InvalidOperationException) { /* fall back to SelectionItemPattern on matching child */ }","preventionTips":["Match item text exactly (case/whitespace).","Prefer SelectionItemPattern for dropdown selection.","Check ValuePattern.IsReadOnly first.","Don't treat drop-list combos as editable text."],"tags":["uiautomation","winforms","combobox","invalid-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"}