{"record":{"id":"8c2550b06575ce01","repo":"dotnet/wpf","slug":"operation-cannot-be-performed-windowshyperlink","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/WindowsHyperlink.cs","lineNumber":429,"sourceCode":"        #region Invoke Pattern\n\n        // Same as clicking on an hyperlink\n        void IInvokeProvider.Invoke()\n        {\n            // Check that button can be clicked.\n            //\n            // This state could change anytime.\n            //\n\n            // Make sure that the control is enabled\n            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            if (!SafeNativeMethods.IsWindowVisible(_hwnd))\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n\n            //\n            // Get the bounding rect for the window.\n            //\n            NativeMethods.Win32Rect BoundingRect = NativeMethods.Win32Rect.Empty;\n            if (!Misc.GetWindowRect(_hwnd, ref BoundingRect))\n            {\n                return;\n            }\n\n            //\n            // All we really need here are the height and the width,\n            // so we don't even need to translate between screen\n            // and client coordinates.\n            //\n            int width = BoundingRect.right - BoundingRect.left;\n            int height = BoundingRect.bottom - BoundingRect.top;","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsHyperlink.cs#L411-L447","documentation":"Invoke on a UI Automation hyperlink proxy throws ElementNotEnabledException if the window is disabled, and InvalidOperationException('Operation cannot be performed') if the hyperlink's underlying HWND is not visible. The library refuses to simulate a click on a hidden control because the operation cannot reach a visible target.","triggerScenarios":"Calling IInvokeProvider.Invoke() on a hyperlink whose hosting window SafeNativeMethods.IsWindowVisible(_hwnd) returns false (e.g. parent window minimized, hyperlink on a hidden/inactive tab, element collapsed).","commonSituations":"UI Automation test scripts invoking links before showing the window; invoking links inside collapsed TabItems or hidden dialog pages; automation racing against window close/minimize.","solutions":["Ensure the hyperlink's window is visible before invoking (show the window, select the tab/page)","Wait for the element to be visible (poll IsOffscreen or wait for window shown) before calling Invoke","Catch InvalidOperationException and re-acquire the element after the UI is shown","Use UIA caching/walkers to skip invisible elements"],"exampleFix":"// before\nhyperlink.Invoke();\n// after\nif (!hyperlink.CurrentPropertyValue(AutomationElement.IsOffscreenProperty, true))\n{\n    hyperlink.Invoke();\n}\nelse\n{\n    // show the parent window/tab first, then retry\n}","handlingStrategy":"try-catch","validationCode":"// before Invoke\nbool visible = !((bool)hyperlink.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));\nif (!visible) { /* show window/tab or abort */ }","typeGuard":null,"tryCatchPattern":"try { ((InvokePattern)hyperlink.GetCurrentPattern(InvokePattern.Pattern)).Invoke(); }\ncatch (InvalidOperationException) { /* element hidden/unavailable: show UI, re-acquire, retry */ }\ncatch (ElementNotEnabledException) { /* enable the element first */ }","preventionTips":["Verify IsOffscreen/IsEnabled before invoking","Wait for the window to be shown/activated before automating","Re-acquire elements after tab/page switches","Prefer UIA events over blind polling on hidden UI"],"tags":["uiautomation","invoke","hidden-element","invalidoperation"],"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"}