dotnet/wpf · error · ArgumentException
SR.GetResourceString(reason)
Error message
SR.GetResourceString(reason)
What it means
Misc.ValidateArgument(cond, reason) throws ArgumentException with the resource string named by 'reason' when the condition is false. It lets UIA client code validate arguments with specific localized error messages identified by resource string names.
Solutions
- Read the resolved message to identify which precondition failed and correct the argument accordingly.
- Validate the argument against the API's documented contract before the call.
- Search the SR resource table for the 'reason' key to see the exact validation rule.
Defensive patterns
Strategy: validation
Validate before calling
// Validate precondition described by the resource key before calling Debug.Assert(cond, reason);
Try / catch
try { uiaApi.Call(arg); }
catch (ArgumentException ex) { MapResourceMessageToFix(ex.Message, arg); } Prevention
- Match each API's documented precondition with a caller-side check.
- Resolve the SR resource key in the message to learn the exact rule broken.
- Centralize UIA call wrappers with argument validation.
When it happens
Trigger: Calling a UIAutomationClient API whose argument validation fails (condition false); the 'reason' string is the SR resource key describing the failed check.
Common situations: Passing arguments that violate a specific documented precondition of a UIA client API (e.g., wrong pattern type, malformed identifier); the message text maps back to which precondition failed.
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
- ' ' is not a valid value for this control.
- E_INVALIDARG
- name
- Operation cannot be performed.
- SR.BeginEndTextContainerMismatch
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/0eb3e4d4dd69ef16.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/Misc.cs:174
}
}
#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);
}
}
// Called by the patterns before accessing .Current
internal static void ValidateCurrent(SafePatternHandle hPattern)
{
if (hPattern.IsInvalid)
{
throw new InvalidOperationException(SR.CacheRequestNeedLiveForProperties);View on GitHub (pinned to 81131a70a4)