{"record":{"id":"0ea2f040e5fffb48","repo":"dotnet/wpf","slug":"elementnotavailableexception-e","errorCode":null,"errorMessage":"ElementNotAvailableException(e)","messagePattern":"ElementNotAvailableException\\(e\\)","errorType":"exception","errorClass":"ElementNotAvailableException","httpStatus":null,"severity":"warning","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs","lineNumber":1301,"sourceCode":"        // or returns true indicating the caller should rethrow the exception.\n        private static bool HandleIAccessibleException(Exception e)\n        {\n            if (e is OutOfMemoryException)\n            {\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                // (Need to check this before Misc.IsCriticalException, since it includes OOM as critical.)\n                throw new ElementNotAvailableException(e);\n            }\n\n            if (e is NullReferenceException)\n            {\n                // Media Player and some other badly-implemented IAccessibles can return the correponding \n                // COM error code (E_POINTER).  This does not actually indicate a null dereference in this \n                // process.\n                throw new ElementNotAvailableException(e);\n            }\n\n            if (Misc.IsCriticalException(e))\n            {\n                return true;\n            }\n\n            COMException comException = e as COMException;\n\n            if (e is NotImplementedException)\n            {\n                // just return on E_NOTIMPL errors\n                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","sourceCodeStart":1283,"sourceCodeEnd":1319,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs#L1283-L1319","documentation":"HandleIAccessibleException converts COMExceptions whose HRESULT is E_POINTER (returned as a NullReferenceException by the wrapper) into ElementNotAvailableException with the original exception attached. Badly-implemented IAccessible servers (e.g. Media Player) return E_POINTER for ordinary failures; in this process it never indicates a real null dereference, so the provider reclassifies it as 'element not available' rather than crashing the client with NullReferenceException.","triggerScenarios":"Any IAccessible property/method call on a server (Media Player and similar) that returns COM error E_POINTER, surfacing as NullReferenceException in the wrapper and being converted to ElementNotAvailableException(e).","commonSituations":"Automating media players or other apps whose MSAA servers return E_POINTER when queried during playback state changes; UIA scripts reading properties of elements in transient states; interop layers that surface COM errors as NREs.","solutions":["Catch ElementNotAvailableException (not NullReferenceException) around UIA calls against such apps and re-find the element","Retry the query once after a short delay — these servers often fail only in transient states","Poll element availability (TryGetClickablePoint / Current failures) before reading many properties","Prefer UIA Core over MSAA proxy path for such apps if possible (UseHttpDelegate / newer provider) to avoid the bad IAccessible"],"exampleFix":"// before\ntry { name = element.Current.Name; }\ncatch (NullReferenceException) { name = null; } // wrong: NRE is reclassified\n// after\ntry { name = element.Current.Name; }\ncatch (ElementNotAvailableException) {\n    element = FindElementAgain();\n    name = element?.Current.Name;\n}","handlingStrategy":"try-catch","validationCode":"// Probe cheaply before bulk reads against flaky MSAA servers\ntry { var _ = element.Current.Name; }\ncatch (ElementNotAvailableException) { element = FindElementAgain(); }","typeGuard":"static bool IsUsable(AutomationElement e) {\n    try { var _ = e.Current.AutomationId; return true; }\n    catch (ElementNotAvailableException) { return false; }\n    catch (InvalidOperationException) { return false; }\n}","tryCatchPattern":"try {\n    name = element.Current.Name;\n} catch (ElementNotAvailableException ex)\n    when (ex.InnerException is NullReferenceException) {\n    // server returned E_POINTER; re-find and retry once\n    element = FindElementAgain();\n    name = element?.Current.Name;\n}","preventionTips":["Catch ElementNotAvailableException, not NullReferenceException, in UIA code paths","Treat E_POINTER from MSAA servers as a state problem, not a code bug","Add retry-with-delay around reads of media-player-style apps","Prefer UIA-native providers over MSAA proxies when the app offers them"],"tags":["uiautomation","msaa","com-interop","e-pointer","nullreference"],"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"}