{"record":{"id":"0eb3e4d4dd69ef16","repo":"dotnet/wpf","slug":"sr-getresourcestring-reason","errorCode":null,"errorMessage":"SR.GetResourceString(reason)","messagePattern":"SR\\.GetResourceString\\(reason\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/Misc.cs","lineNumber":174,"sourceCode":"            }\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            }\n        }\n\n        // Called by the patterns before accessing .Current\n        internal static void ValidateCurrent(SafePatternHandle hPattern)\n        {\n            if (hPattern.IsInvalid)\n            {\n                throw new InvalidOperationException(SR.CacheRequestNeedLiveForProperties);","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/Misc.cs#L156-L192","documentation":"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.","triggerScenarios":"Calling a UIAutomationClient API whose argument validation fails (condition false); the 'reason' string is the SR resource key describing the failed check.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate precondition described by the resource key before calling\nDebug.Assert(cond, reason);","typeGuard":null,"tryCatchPattern":"try { uiaApi.Call(arg); }\ncatch (ArgumentException ex) { MapResourceMessageToFix(ex.Message, arg); }","preventionTips":["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."],"tags":["uiautomation","argument-exception","validation"],"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-22T01:17:13.364Z"}