{"record":{"id":"9d6b9a6c5d615e5a","repo":"AvaloniaUI/Avalonia","slug":"the-property-name-is-readonly","errorCode":null,"errorMessage":"The property {Name} is readonly.","messagePattern":"The property (.+?) is readonly\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/DirectProperty.cs","lineNumber":118,"sourceCode":"                setter,\n                metadata);\n\n            AvaloniaPropertyRegistry.Instance.Register(typeof(TNewOwner), result);\n            return result;\n        }\n\n        /// <inheritdoc/>\n        internal override TValue InvokeGetter(AvaloniaObject instance)\n        {\n            return Getter((TOwner)instance);\n        }\n\n        /// <inheritdoc/>\n        internal override void InvokeSetter(AvaloniaObject instance, BindingValue<TValue> value)\n        {\n            if (Setter == null)\n            {\n                throw new ArgumentException($\"The property {Name} is readonly.\");\n            }\n\n            if (value.HasValue)\n            {\n                Setter((TOwner)instance, value.Value);\n            }\n        }\n\n        /// <inheritdoc/>\n        object? IDirectPropertyAccessor.GetValue(AvaloniaObject instance)\n        {\n            return Getter((TOwner)instance);\n        }\n\n        /// <inheritdoc/>\n        void IDirectPropertyAccessor.SetValue(AvaloniaObject instance, object? value)\n        {\n            if (Setter == null)","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/DirectProperty.cs#L100-L136","documentation":"DirectProperty maps an AvaloniaProperty to a direct CLR getter/setter pair on the owner. When Setter is null the property is read-only, so InvokeSetter (used by the binding/value system to write) throws ArgumentException. This prevents bindings or SetValue calls from writing to a getter-only direct property.","triggerScenarios":"Calling SetValue on a read-only DirectProperty (one registered with `DirectPropertyBuilder<TOwner,TValue>.WithoutSetter()` or no setter supplied). A TwoWay/OneWayToSource binding targeting such a property. InvokeSetter invoked internally by the value store.","commonSituations":"Binding TwoWay to a read-only direct property. Calling control.SetValue(ReadOnlyProp, x). Registering a property without a setter then allowing user input to flow back.","solutions":["Do not write to read-only direct properties; switch the binding to OneWay.","If the property should be writable, register it with a setter lambda in AvaloniaProperty.RegisterDirect.","Guard UI inputs that would push values back through a read-only property."],"exampleFix":"// before:\npublic static readonly DirectProperty<Foo, int> BarProperty =\n    AvaloniaProperty.RegisterDirect<Foo, int>(o => o.Bar);\n// Bar has no setter; later:\nfoo.SetValue(BarProperty, 5); // throws\n\n// after (make writable):\nAvaloniaProperty.RegisterDirect<Foo, int>(o => o.Bar, (o, v) => o.Bar = v);","handlingStrategy":"validation","validationCode":"var dp = (DirectProperty<TOwner, TValue>)property;\nif (dp.Setter is null)\n    throw new ArgumentException($\"{dp.Name} is read-only.\");","typeGuard":"static bool IsWritable(DirectProperty<TOwner, TValue> p) => p.Setter is not null;","tryCatchPattern":null,"preventionTips":["Don't bind TwoWay/OneWayToSource to read-only direct properties.","Register a setter if the property must accept writes.","Check the property's setter availability before SetValue."],"tags":["directproperty","readonly","bindings","argument"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}