dotnet/wpf · error · ArgumentException
E_INVALIDARG
E_INVALIDARG
Error message
SR.InvalidParameter
What it means
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.
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.
Example fix
// before
var child = children[i];
var name = child.Current.Name; // stale child id -> ArgumentException(SR.InvalidParameter)
// after
var fresh = parent.FindAll(TreeScope.Children, Condition.TrueCondition);
foreach (AutomationElement child in fresh)
{
try { Console.WriteLine(child.Current.Name); }
catch (ArgumentException) { /* server rejected child id; skip */ }
} Defensive patterns
Strategy: try-catch
Validate before calling
// Validate a child reference before use:
bool ChildExists(AutomationElement parent, AutomationElement child)
{
var kids = parent.FindAll(TreeScope.Children, Condition.TrueCondition);
foreach (AutomationElement k in kids) if (Automation.Compare(k, child)) return true;
return false;
} Try / catch
try
{
var name = childElement.Current.Name;
}
catch (ArgumentException)
{
// server rejected the child id; child set changed — re-enumerate
childElement = parent.FindFirst(TreeScope.Children, condition);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- E_ACCESSDENIED
- E_OUTOFMEMORY
- E_UNEXPECTED
- name
- ArgumentOutOfRangeException (timeout was Duration.Automatic)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a6263d4bfaeee5bb.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs:1356
// The object does not support the requested property or action. For example,
// a push button returns this value if you request its Value property, since
// it does not have a Value property.
case NativeMethods.E_NOTIMPL:
// just return on E_NOTIMPL errors
return false;
case NativeMethods.E_OUTOFMEMORY:
// Some OLEACC proxies produce out-of-memory for non-critical reasons:
// notably, the treeview proxy will raise this if the target HWND no longer exists,
// GetWindowThreadProcessID fails and it therefore won't be able to allocate shared
// memory in the target process, so it incorrectly assumes OOM.
throw new ElementNotAvailableException(e);
case NativeMethods.E_INVALIDARG:
// One or more arguments were invalid. This error occurs when the caller attempts to identify
// a child object using an identifier that the server does not recognize. This error also results
// when a client attempts to identify a child object within an object that has no children.
throw new ArgumentException(SR.InvalidParameter);
case NativeMethods.E_ACCESSDENIED:
// This is returned when you call get_accValue to get the value of a password control.
throw new UnauthorizedAccessException();
case NativeMethods.E_UNEXPECTED:
// An IAccessible server has been released unexpectedly but still has pending events.
// If the current execution context is inside one of these event handlers it must be
// abandoned.
throw new ElementNotAvailableException(e);
default:
// we want to know when we get an exception we haven't seen before
Debug.Fail(string.Format(CultureInfo.CurrentCulture, "MsaaNativeProvider: IAccessible threw a COMException: {0}", e.Message));
break;
}
}
else if (e is InvalidCastException)View on GitHub (pinned to 81131a70a4)