{"record":{"id":"938f0d357201d1b0","repo":"dotnet/wpf","slug":"rpc-e-serverfault-rpc-e-disconnected-rpc-e-unavailable-disp","errorCode":"RPC_E_SERVERFAULT/RPC_E_DISCONNECTED/RPC_E_UNAVAILABLE/DISP_E_BADINDEX/E_INTERFACEUNKNOWN/E_UNKNOWNWORDERROR/RPC_E_SYS_CALL_FAILED","errorMessage":"ElementNotAvailableException(e)","messagePattern":"ElementNotAvailableException\\(e\\)","errorType":"exception","errorClass":"ElementNotAvailableException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs","lineNumber":1332,"sourceCode":"                return false;\n            }\n            else if (comException != null)\n            {\n                // convert certain COM exceptions to ElementNotAvailable exceptions.\n                // these occur when the underlying UI elements disappear but we are still\n                // holding pointers to them, like when Trident navigates to a new page.\n                int errorCode = comException.ErrorCode;\n\n                switch (errorCode)\n                {\n                    case NativeMethods.RPC_E_SERVERFAULT: // The server threw an exception.\n                    case NativeMethods.RPC_E_DISCONNECTED: // The object invoked has disconnected from its clients.\n                    case NativeMethods.RPC_E_UNAVAILABLE: // The server has disappeared\n                    case NativeMethods.DISP_E_BADINDEX: // Index out of Range (Usually means Children have disappeared)\n                    case NativeMethods.E_INTERFACEUNKNOWN: // The interface is unknown, usually because things have changed.\n                    case NativeMethods.E_UNKNOWNWORDERROR: // An unknown Error code thrown by Word being closed while a search is running\n                    case NativeMethods.RPC_E_SYS_CALL_FAILED: // System call failed during RPC.\n                        throw new ElementNotAvailableException(e);\n\n                    case NativeMethods.E_FAIL:\n                        // An unknown or generic error occurred; treat as a not-impl. (Other methods on the object\n                        // may still work, so don't treat as ElementNotAvailable.)\n                    case NativeMethods.E_MEMBERNOTFOUND:\n                        // The object does not support the requested property or action. For example,\n                        // a push button returns this value if you request its Value property, since\n                        // it does not have a Value property.\n                    case NativeMethods.E_NOTIMPL:\n                        // just return on E_NOTIMPL errors\n                        return false;\n\n                    case NativeMethods.E_OUTOFMEMORY:\n                        // Some OLEACC proxies produce out-of-memory for non-critical reasons:\n                        // notably, the treeview proxy will raise this if the target HWND no longer exists,\n                        // GetWindowThreadProcessID fails and it therefore won't be able to allocate shared\n                        // memory in the target process, so it incorrectly assumes OOM.\n                        throw new ElementNotAvailableException(e);","sourceCodeStart":1314,"sourceCodeEnd":1350,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs#L1314-L1350","documentation":"HandleIAccessibleException maps a specific set of RPC/DISPATCH COM error codes — RPC_E_SERVERFAULT, RPC_E_DISCONNECTED, RPC_E_UNAVAILABLE, DISP_E_BADINDEX, E_INTERFACEUNKNOWN, E_UNKNOWNWORDERROR, RPC_E_SYS_CALL_FAILED — to ElementNotAvailableException with the original exception attached. All of these mean the out-of-process accessibility server effectively disappeared or returned an unusable response, so the element is declared not available to UIA clients.","triggerScenarios":"Any IAccessible call whose server returns one of the listed HRESULTs: the MSAA/OLEACC server crashed (RPC_E_SERVERFAULT), disconnected (RPC_E_DISCONNECTED), vanished (RPC_E_UNAVAILABLE), children indices became stale (DISP_E_BADINDEX), interfaces changed (E_INTERFACEUNKNOWN), Word closed mid-search (E_UNKNOWNWORDERROR), or a system call failed during RPC (RPC_E_SYS_CALL_FAILED).","commonSituations":"Target application crashes or exits during automation; Office (Word) documents closing while UIA searches run; long-running automation sessions outliving the target UI; cross-process RPC to the accessibility server breaking during heavy UI churn; child collections shrinking between discovery and access.","solutions":["Catch ElementNotAvailableException and re-acquire the element by AutomationId/RuntimeId, then retry with bounded retries","Detect target app exit (Process.HasExited / UIA WindowClosedEvent) before assuming the element should exist","Use CacheRequest to fetch all needed properties in one call, shrinking the window for mid-call disconnections","Slow down / debounce UIA queries against targets known to churn (Word documents, transient windows) and subscribe to structure-changed events instead of polling"],"exampleFix":"// before\nvar value = element.Current.Value; // throws if server disconnected mid-session\n// after\nstring value;\ntry {\n    value = element.Current.Value;\n} catch (ElementNotAvailableException) when (RetryOnce()) {\n    value = FindElement(id).Current.Value;\n}","handlingStrategy":"retry","validationCode":"// Verify the hosting process still exists before touching its elements\nif (targetProcess == null || targetProcess.HasExited) return null;\n// And verify the element still resolves:\nvar found = root.FindFirst(TreeScope.Descendants,\n    new PropertyCondition(AutomationElement.AutomationIdProperty, id));\nif (found == null) return null;","typeGuard":"static bool IsElementAlive(AutomationElement e) {\n    try { var _ = e.GetRuntimeId(); return true; }\n    catch (ElementNotAvailableException) { return false; }\n}","tryCatchPattern":"const int MaxRetries = 3;\nfor (int i = 0; i < MaxRetries; i++) {\n    try { result = element.Current.Value; break; }\n    catch (ElementNotAvailableException ex)\n        when (ex.InnerException is COMException ce &&\n              (ce.HResult == unchecked((int)0x80010108) || // RPC_E_DISCONNECTED\n               ce.HResult == unchecked((int)0x800706BA) || // RPC_E_SERVERFAULT-ish\n               ce.HResult == unchecked((int)0x800706BE))) {\n        element = FindElementAgain();\n        if (element == null) throw; // target truly gone\n    }\n}","preventionTips":["Monitor the target process lifetime (Process.Exited) alongside UIA calls","Subscribe to WindowClosedEvent/StructureChangedEvent instead of polling","Use CacheRequest to fetch everything in a single RPC","Add bounded retry with backoff around automation sessions of Office apps","Serialize UIA work against a target so Word documents aren't touched mid-close"],"tags":["uiautomation","msaa","com-interop","rpc","server-disconnected"],"backgroundTag":"stale-ui-automation-element","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"}