dotnet/wpf · error · ArgumentException
SR.GenericInvalidArgument (formatted with argName)
Error message
SR.GenericInvalidArgument (formatted with argName)
What it means
Misc.ThrowInvalidArgument is a helper that throws ArgumentException with the generic SR.GenericInvalidArgument message formatted with the supplied argument name. It is the UIAutomationClient's shorthand for reporting an invalid method argument to callers.
Solutions
- Read the argument name in the message and validate that value at the call site before invoking the UIA API.
- Check for null/empty or wrong-type values being passed to the AutomationElement/pattern method indicated.
- Consult the UIA API documentation for the parameter's required format or allowed values.
Example fix
// before client.SomeUiaApi(value); // after if (string.IsNullOrEmpty(value)) throw new ArgumentNullException(nameof(value)); client.SomeUiaApi(value);
Defensive patterns
Strategy: validation
Validate before calling
if (arg == null || string.IsNullOrEmpty(arg as string)) throw new ArgumentNullException(nameof(arg));
Type guard
static bool IsValidArg<T>(T arg) where T : class => arg != null;
Try / catch
try { uiaApi.Call(arg); }
catch (ArgumentException ex) { HandleInvalidArgument(ex.ParamName ?? "unknown", arg); } Prevention
- Validate arguments (null, type, format) before calling UIA client APIs.
- Read ex.ParamName from ArgumentExceptions to pinpoint the offending value.
- Keep UIA identifiers (patterns, properties) sourced from their static definitions.
When it happens
Trigger: Any internal UIAutomationClient code path that detects an invalid argument and calls Misc.ThrowInvalidArgument(argName) — the exception message includes the offending parameter name.
Common situations: Passing wrong-typed or out-of-contract values into UIA client APIs (e.g., null or malformed handles, invalid property/pattern identifiers) which the library validates via this helper.
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_INVALIDARG
- name
- SR.BeginEndTextContainerMismatch
- SR.Format(SR.InvalidDataTypeOfParameter, " DateTime or…
- SR.Format(SR.PropertyConditionIncorrectType…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1aa242692bf14046.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/Misc.cs:166
{
Debug.Fail("missing client-side pattern wrapper");
return null;
}
else
{
// false -> not cached. (Cached goes via AutomationElement.GetCachedPattern, not here)
return pi.ClientSideWrapper(el, hPattern, false);
}
}
#endregion Interface & Property Wrapping
#region Param validation & Error related
// Throw an argument Exception with a generic error
internal static void ThrowInvalidArgument(string argName)
{
throw new ArgumentException(SR.Format(SR.GenericInvalidArgument, argName));
}
// Check that specified condition is true; if not, throw exception
internal static void ValidateArgument(bool cond, string reason)
{
if (!cond)
{
throw new ArgumentException(SR.GetResourceString(reason, null));
}
}
// Called by the patterns before accessing .Cache
internal static void ValidateCached(bool cached)
{
if (!cached)
{
throw new InvalidOperationException(SR.CacheRequestNeedCache);
}View on GitHub (pinned to 81131a70a4)