{"record":{"id":"36e1ad736d3917c2","repo":"dotnet/wpf","slug":"sr-valuereadonly-windowsrichedit","errorCode":null,"errorMessage":"SR.ValueReadonly","messagePattern":"SR\\.ValueReadonly","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEdit.cs","lineNumber":169,"sourceCode":"\n            return base.GetElementProperty(idProp);\n        }\n        #endregion ProxySimple Interface\n\n        #region Value Pattern\n\n        // Sets the text of the edit.\n        void IValueProvider.SetValue(string str)\n        {\n            // Check if the window is disabled\n            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","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEdit.cs#L151-L187","documentation":"WindowsRichEdit's IValueProvider.SetValue refuses to change the text of a rich edit control created with the ES_READONLY window style. Setting a value into a read-only edit box is not permitted, so it throws InvalidOperationException(SR.ValueReadonly), mirroring how a user cannot type into the control.","triggerScenarios":"Calling UIA ValuePattern.SetValue(string) on a rich edit control whose WindowStyle includes ES_READONLY.","commonSituations":"Automating forms where the field is intentionally read-only (display-only fields, license text boxes), or applications that flip ES_READONLY on at runtime while automation scripts still try to fill the field.","solutions":["Skip SetValue for read-only fields; if you own the app, remove ES_READONLY or temporarily clear it before automation","Use the target application's own API/IPC to update the data instead of UIA","Check WindowStyle for ES_READONLY before calling SetValue and branch accordingly","If the field should be editable, fix the app to not apply ES_READONLY"],"exampleFix":"// before\neditBox.GetCurrentPattern(ValuePattern.Pattern).SetValue(text); // throws if ES_READONLY\n// after\nif ((int)editBoxNative.WindowStyle & ES_READONLY == 0)\n    editBox.GetCurrentPattern(ValuePattern.Pattern).SetValue(text);\nelse\n    HandleReadOnlyField();","handlingStrategy":"validation","validationCode":"bool CanSetValue(AutomationElement e) { var p = e.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; return p != null && p.Current.IsReadOnly == false; }","typeGuard":"bool IsEditable(AutomationElement e) => e.TryGetCurrentPattern(ValuePattern.Pattern, out var p) && !((ValuePattern)p).Current.IsReadOnly;","tryCatchPattern":"try { valuePattern.SetValue(text); } catch (InvalidOperationException) { /* field is read-only (ES_READONLY) */ }","preventionTips":["Check ValuePattern.IsReadOnly before every SetValue","Skip read-only display fields in form-filling automation","Use the application's own API when a field must be updated programmatically but is read-only in UI"],"tags":["uiautomation","readonly","richedit","value-pattern"],"backgroundTag":"operation-not-supported","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"}