dotnet/wpf · error · System.InvalidOperationException
SR.ValueReadonly
Error message
SR.ValueReadonly
What it means
InvalidOperationException(SR.ValueReadonly) is thrown by the internal static SetValue when the ListView does not have label editing enabled (ListViewEditable false). The ValuePattern edit is implemented by launching in-place label editing, so a non-editable list means its values are read-only.
Solutions
- Set ListView.LabelEdit = true on the target control to enable label editing.
- Use BeginEdit/label-edit UI interaction instead of ValuePattern on non-editable lists.
- Catch InvalidOperationException and treat the value as read-only.
- Verify IsReadOnlyProperty on the ValuePattern before calling SetValue.
Example fix
// before listView1.Items[0].Text = "x"; // via UIA SetValue -> fails when LabelEdit is false // after listView1.LabelEdit = true; // enables LVS_EDITLABELS so UIA SetValue works
Defensive patterns
Strategy: validation
Validate before calling
var readOnly = (bool)item.CurrentPropertyValue(ValuePattern.IsReadOnlyProperty);
if (readOnly) throw new InvalidOperationException("value is read-only (LabelEdit disabled)"); Try / catch
try { valuePattern.SetValue(text); }
catch (InvalidOperationException) { /* read-only: use app API or enable LabelEdit */ } Prevention
- Check ValuePattern.IsReadOnlyProperty before SetValue
- Set ListView.LabelEdit = true in the app when editing is required
- Do not assume list items are editable
When it happens
Trigger: Calling SetValue (ValuePattern) on a ListView item whose control lacks LVS_EDITLABELS (ListViewEditable returns false).
Common situations: Default WinForms ListView (LabelEdit=false) automated with a SetValue call; test scripts assuming all list items are editable; app changed LabelEdit at runtime or across versions.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- SR.OperationCannotBePerformed
- ' ' is not a valid value for this control.
- Element is not enabled.
- Element is not enabled.
- Element is not enabled.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d9c046ae1519ec71.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewItem.cs:751
mask = NativeMethods.LVIF_GROUPID,
iItem = lvItem
};
if (XSendMessage.GetItem(hwnd, ref item))
{
return item.iGroupID;
}
return -1;
}
internal static void SetValue (string val, IntPtr hwnd, int item)
{
ArgumentNullException.ThrowIfNull(val);
if (!WindowsListView.ListViewEditable (hwnd))
{
throw new InvalidOperationException(SR.ValueReadonly);
}
Misc.SetFocus(hwnd);
// set focus to the item
WindowsListView.SetItemFocused (hwnd, item);
// retrieve edit window
IntPtr hwndEdit = WindowsListView.ListViewEditLabel (hwnd, item);
if (IntPtr.Zero == hwndEdit)
{
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
// re-use editbox proxy to do the job
// Note: we will pass null and -1 for some of the parameters
// this is ok, since the only thing that matters to us is an ability to set the textView on GitHub (pinned to 81131a70a4)