{"record":{"id":"1aa242692bf14046","repo":"dotnet/wpf","slug":"sr-genericinvalidargument-formatted-with-argname","errorCode":null,"errorMessage":"SR.GenericInvalidArgument (formatted with argName)","messagePattern":"SR\\.GenericInvalidArgument \\(formatted with argName\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/Misc.cs","lineNumber":166,"sourceCode":"            {\n                Debug.Fail(\"missing client-side pattern wrapper\");\n                return null;\n            }\n            else\n            {\n                // false -> not cached. (Cached goes via AutomationElement.GetCachedPattern, not here)\n                return pi.ClientSideWrapper(el, hPattern, false);\n            }\n        }\n\n        #endregion Interface & Property Wrapping\n\n        #region Param validation & Error related\n\n        // Throw an argument Exception with a generic error\n        internal static void ThrowInvalidArgument(string argName)\n        {\n            throw new ArgumentException(SR.Format(SR.GenericInvalidArgument, argName));\n        }\n\n        // Check that specified condition is true; if not, throw exception\n        internal static void ValidateArgument(bool cond, string reason)\n        {\n            if (!cond)\n            {\n                throw new ArgumentException(SR.GetResourceString(reason, null));\n            }\n        }\n\n        // Called by the patterns before accessing .Cache\n        internal static void ValidateCached(bool cached)\n        {\n            if (!cached)\n            {\n                throw new InvalidOperationException(SR.CacheRequestNeedCache);\n            }","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/Misc.cs#L148-L184","documentation":"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.","triggerScenarios":"Any internal UIAutomationClient code path that detects an invalid argument and calls Misc.ThrowInvalidArgument(argName) — the exception message includes the offending parameter name.","commonSituations":"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.","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."],"exampleFix":"// before\nclient.SomeUiaApi(value);\n// after\nif (string.IsNullOrEmpty(value)) throw new ArgumentNullException(nameof(value));\nclient.SomeUiaApi(value);","handlingStrategy":"validation","validationCode":"if (arg == null || string.IsNullOrEmpty(arg as string)) throw new ArgumentNullException(nameof(arg));","typeGuard":"static bool IsValidArg<T>(T arg) where T : class => arg != null;","tryCatchPattern":"try { uiaApi.Call(arg); }\ncatch (ArgumentException ex) { HandleInvalidArgument(ex.ParamName ?? \"unknown\", arg); }","preventionTips":["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."],"tags":["uiautomation","argument-exception","invalid-argument"],"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"}