{"record":{"id":"a6263d4bfaeee5bb","repo":"dotnet/wpf","slug":"e-invalidarg-sr-invalidparameter","errorCode":"E_INVALIDARG","errorMessage":"SR.InvalidParameter","messagePattern":"SR\\.InvalidParameter","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs","lineNumber":1356,"sourceCode":"                        // 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);\n                        \n                    case NativeMethods.E_INVALIDARG:\n                        // One or more arguments were invalid. This error occurs when the caller attempts to identify\n                        // a child object using an identifier that the server does not recognize. This error also results\n                        // when a client attempts to identify a child object within an object that has no children.\n                        throw new ArgumentException(SR.InvalidParameter);\n\n                    case NativeMethods.E_ACCESSDENIED:\n                        // This is returned when you call get_accValue to get the value of a password control.\n                        throw new UnauthorizedAccessException();\n\n                    case NativeMethods.E_UNEXPECTED:\n                        // An IAccessible server has been released unexpectedly but still has pending events.\n                        // If the current execution context is inside one of these event handlers it must be \n                        // abandoned.\n                        throw new ElementNotAvailableException(e);\n\n                    default:\n                        // we want to know when we get an exception we haven't seen before\n                        Debug.Fail(string.Format(CultureInfo.CurrentCulture, \"MsaaNativeProvider: IAccessible threw a COMException: {0}\", e.Message));\n                        break;\n                }\n            }\n            else if (e is InvalidCastException)","sourceCodeStart":1338,"sourceCodeEnd":1374,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs#L1338-L1374","documentation":"The MSAA/IAccessible server returned E_INVALIDARG, and the provider rethrows it as ArgumentException(SR.InvalidParameter). Per the MSAA contract this occurs when the caller identifies a child object using an identifier (childId/varChild) the server does not recognize, or attempts to identify a child within an object that has no children. The library maps it to ArgumentException because it almost always indicates a bad child id being passed down to the native provider.","triggerScenarios":"An Accessible method calls into IAccessible with a self/child id that the native server rejects — e.g. enumerating children of a leaf element, using a stale child id after the element's children changed, or an upstream UIA cache/lookup passing an invalid childId.","commonSituations":"UIA clients walking child collections of MSAA-mapped controls while the control's child set changes (tree/list rebuilding); providers for controls that report children inconsistently; automation scripts that cache child elements across UI mutations.","solutions":["Re-enumerate children fresh (FindAll(TreeScope.Children)) instead of reusing cached child elements/ids after the UI changed.","Catch ElementNotAvailableException/ArgumentException around child navigation and treat as 'child no longer exists' rather than a programming bug.","If you own the provider, verify the childId passed to accChild/get_accChild calls matches what the server advertised (self id 0 vs 1-based child ids).","Update .NET/WPF — some OLEACC proxy quirks with child id handling were fixed in later framework servicing releases."],"exampleFix":"// before\nvar child = children[i];\nvar name = child.Current.Name; // stale child id -> ArgumentException(SR.InvalidParameter)\n// after\nvar fresh = parent.FindAll(TreeScope.Children, Condition.TrueCondition);\nforeach (AutomationElement child in fresh)\n{\n    try { Console.WriteLine(child.Current.Name); }\n    catch (ArgumentException) { /* server rejected child id; skip */ }\n}","handlingStrategy":"try-catch","validationCode":"// Validate a child reference before use:\nbool ChildExists(AutomationElement parent, AutomationElement child)\n{\n    var kids = parent.FindAll(TreeScope.Children, Condition.TrueCondition);\n    foreach (AutomationElement k in kids) if (Automation.Compare(k, child)) return true;\n    return false;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var name = childElement.Current.Name;\n}\ncatch (ArgumentException)\n{\n    // server rejected the child id; child set changed — re-enumerate\n    childElement = parent.FindFirst(TreeScope.Children, condition);\n}","preventionTips":["Re-enumerate children with FindAll after any UI mutation instead of reusing cached child ids/elements.","Match provider semantics: self is childId 0, children are 1-based when writing providers.","Treat ArgumentException during navigation as 'element gone', not a bug.","Keep WPF/.NET serviced — child-id handling in legacy OLEACC proxies improved over releases."],"tags":["uiautomation","wpf","msaa","argument-exception","child-id"],"backgroundTag":"invalid-argument-value","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"}