{"record":{"id":"b75b6143171b3aa8","repo":"AvaloniaUI/Avalonia","slug":"the-property-property-name-is-readonly","errorCode":null,"errorMessage":"The property {property.Name} is readonly.","messagePattern":"The property (.+?) is readonly\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/AvaloniaObject.cs","lineNumber":888,"sourceCode":"            }\n            else\n            {\n                builder.Append(ToString());\n            }\n        }\n\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        private static void ValidatePriority(BindingPriority priority)\n        {\n            if (priority < BindingPriority.Animation || priority >= BindingPriority.Inherited)\n                ThrowInvalidPriority(priority);\n        }\n\n        private static void ThrowIfReadOnly(AvaloniaProperty property)\n        {\n            if (property.IsReadOnly)\n            {\n                throw new ArgumentException($\"The property {property.Name} is readonly.\");\n            }\n        }\n\n        private static void ThrowInvalidPriority(BindingPriority priority)\n        {\n            throw new ArgumentException($\"Invalid priority ${priority}\", nameof(priority));\n        }\n    }\n}\n","sourceCodeStart":870,"sourceCodeEnd":898,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/AvaloniaObject.cs#L870-L898","documentation":"Thrown by AvaloniaObject.ThrowIfReadOnly when attempting to write a property whose IsReadOnly flag is set. ReadOnly properties (typically registered with RegisterReadOnly and exposing only a public getter) reject local writes and bindings.","triggerScenarios":"Calling SetValue/Bind on a ReadOnlyProperty; XAML or styling trying to assign a value to a read-only property; a style setter targeting a read-only property.","commonSituations":"Confusing a read-only property (computed/managed by the control) with a settable one; targeting properties like Visual.Bounds or control computed-state in styles.","solutions":["Do not bind or set read-only properties; use the control's API that internally updates them.","If you own the property and need external writes, register it as read-write or expose a protected setter key.","In XAML/styles, remove setters that target read-only properties."],"exampleFix":"// before\ncontrol.SetValue(Visual.BoundsProperty, new Rect(...)); // Bounds is read-only\n\n// after\n// drive the bounds through layout, not by setting the property\ncontrol.InvalidateMeasure();","handlingStrategy":"validation","validationCode":"if (property.IsReadOnly)\n    throw new InvalidOperationException($\"{property.Name} is read-only; use the control API instead\");","typeGuard":"static bool IsWritable(AvaloniaProperty p) => !p.IsReadOnly;","tryCatchPattern":"try { obj.SetValue(property, value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"readonly\"))\n{ /* cannot write; adjust caller */ }","preventionTips":["Check property.IsReadOnly before binding/setting in generic code.","Drive read-only properties through their owning control's methods."],"tags":["property-system","avaloniaobject","readonly","argument"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}