{"record":{"id":"fd0ad9a5ec636d3c","repo":"dotnet/wpf","slug":"operation-cannot-be-performed-windowsformslinklabel","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/WindowsFormsLinkLabel.cs","lineNumber":115,"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            Misc.SetFocus(_hwnd);\n\n            NativeMethods.Win32Point pt = new NativeMethods.Win32Point();\n            if (GetClickablePoint(out pt, false))\n            {\n                Misc.MouseClick(pt.x, pt.y);\n            }\n        }\n\n        #endregion Invoke Pattern\n   }\n}\n","sourceCodeStart":97,"sourceCodeEnd":130,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsFormsLinkLabel.cs#L97-L130","documentation":"After the enabled check, WindowsFormsLinkLabel.Invoke verifies the control is visible with IsWindowVisible; a hidden LinkLabel cannot be clicked, so it throws InvalidOperationException with SR.OperationCannotBePerformed ('Operation cannot be performed').","triggerScenarios":"Calling Invoke() on a LinkLabel whose HWND is not visible — control Visible=false, parent form minimized/hidden, or control on a non-active tab page.","commonSituations":"Automating forms on hidden or minimized windows; clicking links on inactive TabPages; UIA scripts running before the form is shown (pre-Shown).","solutions":["Make the control visible before invoking: show the form and set linkLabel.Visible = true.","Check element.Current.IsOffscreen == false before calling Invoke.","Catch InvalidOperationException and either show the window first or use an alternate non-UI path (call the underlying action directly).","Activate/restore the parent window if it is minimized."],"exampleFix":"// before\ninvokePattern.Invoke();\n// after\nif (!element.Current.IsOffscreen)\n{\n    invokePattern.Invoke();\n}\nelse\n{\n    form.Show(); // or bring to correct tab\n    invokePattern.Invoke();\n}","handlingStrategy":"validation","validationCode":"bool visible = !element.Current.IsOffscreen && element.Current.IsControlElement;\nif (!visible) { /* show form / activate tab before Invoke */ }","typeGuard":null,"tryCatchPattern":"try { invokePattern.Invoke(); }\ncatch (InvalidOperationException) { BringTargetIntoView(element); invokePattern.Invoke(); }","preventionTips":["Verify IsOffscreen == false before invoking hidden-window controls","Show/activate the form or switch to the correct TabPage first","Avoid automating controls before the form's Shown event","Prefer calling the app-level action directly when the UI is intentionally hidden"],"tags":["uiautomation","winforms","invoke","element-invisible"],"backgroundTag":"invalid-state-transition","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"}