{"record":{"id":"43f283dccec1a0d8","repo":"dotnet/wpf","slug":"sr-format-sr-notavalidvalue-str","errorCode":null,"errorMessage":"SR.Format(SR.NotAValidValue, str)","messagePattern":"SR\\.Format\\(SR\\.NotAValidValue, str\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEdit.cs","lineNumber":180,"sourceCode":"            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            if (Misc.IsBitSet(WindowStyle, NativeMethods.ES_READONLY))\n            {\n                throw new InvalidOperationException(SR.ValueReadonly);\n            }\n\n            // check if control only accepts numbers\n            if (Misc.IsBitSet(WindowStyle, NativeMethods.ES_NUMBER) && !WindowsFormsHelper.IsWindowsFormsControl(_hwnd))\n            {\n                // check if string contains any non-numeric characters.\n                foreach (char ch in str)\n                {\n                    if (char.IsLetter(ch))\n                    {\n                        throw new ArgumentException(SR.Format(SR.NotAValidValue, str), \"val\");\n                    }\n                }\n            }\n\n            // Text/edit box should not enter more characters than what is allowed through keyboard.\n            // Determine the max number of chars this editbox accepts\n\n            int result = Misc.ProxySendMessageInt(_hwnd, NativeMethods.EM_GETLIMITTEXT, IntPtr.Zero, IntPtr.Zero);\n            if (result < str.Length)\n            {\n                throw new InvalidOperationException (SR.OperationCannotBePerformed);\n            }\n\n            // Send the message...\n            result = Misc.ProxySendMessageInt(_hwnd, NativeMethods.WM_SETTEXT, IntPtr.Zero, new StringBuilder(str));\n            if (result != 1)\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEdit.cs#L162-L198","documentation":"When a rich edit control has the ES_NUMBER style, SetValue validates that the new string contains no alphabetic characters before sending it. A string containing letters is not a valid numeric value for that control, so it throws ArgumentException(SR.Format(SR.NotAValidValue, str)) with parameter name \"val\".","triggerScenarios":"Calling ValuePattern.SetValue(str) on an ES_NUMBER-styled rich edit with a string containing any letter (e.g. \"12a4\").","commonSituations":"Automation feeding unvalidated user input or formatted strings (\"12 kg\", \"1.5x\") into numeric-only fields; locale-specific digit/letter characters sneaking into values.","solutions":["Strip or correct non-numeric characters before calling SetValue on ES_NUMBER fields","Use char.IsLetter checks in your own pre-validation to reject bad input early","If the field must accept non-numeric text, change the control style (remove ES_NUMBER) in the target app","Parse the numeric portion (e.g. double.TryParse) and set only the numeric string"],"exampleFix":"// before\nvaluePattern.SetValue(\"12 kg\"); // ArgumentException: NotAValidValue\n// after\nstring numeric = new string(text.Where(c => !char.IsLetter(c)).ToArray());\nif (!string.IsNullOrWhiteSpace(numeric))\n    valuePattern.SetValue(numeric);","handlingStrategy":"validation","validationCode":"bool IsNumericSafeForEsNumber(string s) => !s.Any(char.IsLetter);","typeGuard":"bool IsNumericText(string s) => s.All(c => !char.IsLetter(c));","tryCatchPattern":"try { valuePattern.SetValue(val); } catch (ArgumentException) { /* value contains letters on an ES_NUMBER field */ }","preventionTips":["Sanitize input to digits/separators before writing to numeric-only fields","Detect ES_NUMBER-style fields (control type Edit with numeric semantics) and validate first","Use invariant formatting when converting numbers to strings for automation"],"tags":["uiautomation","richedit","argument","numeric-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-21T21:30:21.729Z"}