{"record":{"id":"47af8d6e4803f814","repo":"dotnet/wpf","slug":"sr-operationcannotbeperformed-accessible","errorCode":null,"errorMessage":"SR.OperationCannotBePerformed","messagePattern":"SR\\.OperationCannotBePerformed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs","lineNumber":533,"sourceCode":"                        throw;\n                    }\n                    return \"\";\n                }\n            }\n            set\n            {\n                try\n                {\n                    _acc.set_accValue(_idChild, value);\n                }\n                catch (Exception e)\n                {\n                    if (HandleIAccessibleException(e))\n                    {\n                        throw;\n                    }\n\n                    throw new InvalidOperationException(SR.OperationCannotBePerformed, e);\n                }\n            }\n        }\n\n        // Return the Rect that bounds this element in screen coordinates\n        internal Rect Location\n        {\n            get\n            {\n                NativeMethods.Win32Rect rcW32 = GetLocation(_acc, _idChild);\n                return rcW32.ToRect(false);\n            }\n        }\n\n        internal static Accessible GetFullAccessibleChildByIndex(Accessible accParent, int index)\n        {\n            int childCount = 0; \n            object[] accChildren = Accessible.GetAccessibleChildren(accParent.IAccessible, out childCount);","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs#L515-L551","documentation":"The MSAA Accessible wrapper (client-side provider proxies) converts an unhandled IAccessible COM failure into InvalidOperationException(SR.OperationCannotBePerformed, e). When HandleIAccessibleException decides the exception should propagate, or rethrows generically, callers see 'the operation cannot be performed' with the original COM exception as InnerException.","triggerScenarios":"Any proxied IAccessible call (property get, navigation, hit test) that returns a COM error not recognized/recoverable by HandleIAccessibleException — e.g. the underlying OLEACC/MSAA object returned DISP_E_MEMBERNOTFOUND, E_FAIL, or the accessible object was destroyed mid-call.","commonSituations":"Automating legacy Win32/MSAA applications whose accessible objects die during UI updates; mixed-technology UIs (WinForms/Win32) with unstable accessibility implementations; calls made while the target window is being torn down.","solutions":["Inspect InnerException for the COM HRESULT to identify the actual failure and address it.","Catch InvalidOperationException around Accessible property/method use and retry after the UI settles.","Re-acquire the AutomationElement/Accessible reference — the underlying MSAA object is likely stale.","If the app is yours, fix the provider so its IAccessible implementation returns S_OK or valid errors instead of failing."],"exampleFix":"// before\nvar rect = accessible.Location; // MSAA call failed\n// after\ntry { var rect = accessible.Location; }\ncatch (InvalidOperationException ex) when (ex.InnerException != null)\n{\n    log.Warn($\"MSAA call failed: {ex.InnerException.Message}\");\n    accessible = ReacquireAccessible(element);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var result = DoMsaaCall(accessible);\n}\ncatch (InvalidOperationException ex) when (ex.InnerException is COMException ce)\n{\n    log.Warn($\"MSAA op failed HRESULT=0x{ce.ErrorCode:X8}\");\n    accessible = ReacquireAccessible(element); // stale proxy; re-acquire\n}","preventionTips":["Inspect InnerException (COMException) for the HRESULT to diagnose the root cause","Avoid touching accessible objects while the target window is being created/destroyed","Add retry-with-delay around MSAA-heavy operations on dynamic UIs","Prefer UIA (UIAutomationClient) over raw MSAA proxies on newer applications"],"tags":["uiautomation","msaa","iaccessible","com-interop","invalid-operation"],"backgroundTag":"upstream-api-error","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"}