{"record":{"id":"9a3ce245be96faa0","repo":"dotnet/wpf","slug":"value-is-read-only","errorCode":null,"errorMessage":"Value is read-only.","messagePattern":"Value is read-only\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsEditBox.cs","lineNumber":271,"sourceCode":"        {\n            return base.EventToWinEvent(idEvent);\n        }\n\n        #endregion\n\n        #region Value Pattern\n\n        // Sets the text of the edit.\n        void IValueProvider.SetValue (string str)\n        {\n            // Ensure that the edit box and all its parents are enabled.\n            Misc.CheckEnabled(_hwnd);\n\n            int styles = WindowStyle;\n\n            if (Misc.IsBitSet(styles, NativeMethods.ES_READONLY))\n            {\n                throw new InvalidOperationException(SR.ValueReadonly);\n            }\n\n            // check if control only accepts numbers\n            if (Misc.IsBitSet(styles, NativeMethods.ES_NUMBER))\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            int result = Misc.ProxySendMessageInt(_hwnd, NativeMethods.EM_GETLIMITTEXT, IntPtr.Zero, IntPtr.Zero);","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsEditBox.cs#L253-L289","documentation":"The Win32 edit box proxy throws InvalidOperationException(ValueReadonly) from IValueProvider.SetValue when the edit control has the ES_READONLY window style. UIA forbids writing to a control that the underlying Win32 control itself marks read-only.","triggerScenarios":"Calling IValueProvider.SetValue on a WindowsEditBox whose window styles include ES_READONLY (set via EM_SETREADONLY or created with the style).","commonSituations":"Automating a disabled/read-only text field such as a computed field, license key display, or a form field the app locked after data entry; an application dynamically set EM_SETREADONLY before the script attempted input.","solutions":["Enable the control first via EM_SETREADOFFSET/no — send EM_SETREADONLY (wParam=0) to the HWND if you own the application.","Use the IValueProvider.IsReadOnly property to check before calling SetValue and skip or warn.","If the field must accept input, fix the application so the control is not read-only.","Automate the underlying data source (e.g. API or config) instead of typing into the read-only UI."],"exampleFix":"// before\nvar valuePattern = editBox.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;\nvaluePattern.SetValue(\"text\"); // InvalidOperationException: Value is read-only.\n// after\nvar vp = (ValuePattern)editBox.GetCurrentPattern(ValuePattern.Pattern);\nif (!vp.Current.IsReadOnly)\n{\n    vp.SetValue(\"text\");\n}","handlingStrategy":"validation","validationCode":"var vp = (ValuePattern)el.GetCurrentPattern(ValuePattern.Pattern);\nif (vp.Current.IsReadOnly) return; // skip SetValue","typeGuard":null,"tryCatchPattern":"try { vp.SetValue(text); }\ncatch (InvalidOperationException) { /* control is read-only; log and skip */ }","preventionTips":["Always check IValueProvider.IsReadOnly before SetValue.","Check window styles for ES_READONLY when you own the control.","Don't script input into locked/computed fields."],"tags":["uiautomation","winforms","editbox","read-only"],"backgroundTag":"invalid-state-transition","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"}