{"record":{"id":"947d5471c841a1ba","repo":"AvaloniaUI/Avalonia","slug":"setter-property-must-be-set","errorCode":null,"errorMessage":"Setter.Property must be set.","messagePattern":"Setter\\.Property must be set\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Styling/Setter.cs","lineNumber":74,"sourceCode":"            {\n                (value as ISetterValue)?.Initialize(this);\n                _value = value;\n            }\n        }\n\n        AvaloniaProperty IValueEntry.Property => EnsureProperty();\n\n        public override string ToString() => $\"Setter: {Property} = {Value}\";\n\n        void IValueEntry.Unsubscribe() { }\n\n        [UnconditionalSuppressMessage(\"Trimming\", \"IL2026\", Justification = TrimmingMessages.ImplicitTypeConversionSupressWarningMessage)]\n        internal override ISetterInstance Instance(IStyleInstance instance, StyledElement target)\n        {\n            if (target is not AvaloniaObject ao)\n                throw new InvalidOperationException(\"Don't know how to instance a style on this type.\");\n            if (Property is null)\n                throw new InvalidOperationException(\"Setter.Property must be set.\");\n            if (Property.IsDirect && instance.HasActivator)\n                throw new InvalidOperationException(\n                    $\"Cannot set direct property '{Property}' in '{instance.Source}' because the style has an activator.\");\n            if (Property.IsClassesBindingProperty(out var classPropertyName) && instance.HasActivator)\n                throw new InvalidOperationException(\n                        $\"Cannot set Class Binding property '(Classes.{classPropertyName})' in '{instance.Source}' because the style has an activator.\");\n\n            if (Value is BindingBase binding)\n                return SetBinding((StyleInstance)instance, ao, binding);\n            else if (Value is ITemplate template && !typeof(ITemplate).IsAssignableFrom(Property.PropertyType))\n                return new PropertySetterTemplateInstance(Property, template);\n            else if (!Property.IsValidValue(Value))\n                throw new InvalidCastException($\"Setter value '{Value}' is not a valid value for property '{Property}'.\");\n            else if (Property.IsDirect)\n                return SetDirectValue(target);\n            else\n                return this;\n        }","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Styling/Setter.cs#L56-L92","documentation":"Thrown by Setter.Instance when the Setter's Property is null at the time the style is attached. A Setter must reference a valid AvaloniaProperty to apply; a null Property means the setter was declared without specifying what to set. This fires during style attachment (late, at apply time).","triggerScenarios":"Creating `new Setter()` and adding it to a style without ever setting `.Property`; AXAML `<Setter Value=\"...\"/>` missing the `Property` attribute; object initializer that omits Property.","commonSituations":"AXAML Setter missing the Property attribute; data-binding the Property and it not being resolved; copy-paste Setter template and forgetting the property name.","solutions":["Set Property on every Setter, e.g. `<Setter Property=\"Background\" Value=\"Red\"/>` or `new Setter(Control.BackgroundProperty, Brushes.Red)`.","Audit AXAML for `<Setter>` elements lacking a Property attribute.","If constructing in C#, use the (property, value) constructor to guarantee both are set."],"exampleFix":"// before\nstyle.Setters.Add(new Setter { Value = Brushes.Red });\n\n// after\nstyle.Setters.Add(new Setter(Control.BackgroundProperty, Brushes.Red));","handlingStrategy":"validation","validationCode":"foreach (var setter in style.Setters.OfType<Setter>())\n    if (setter.Property is null)\n        throw new InvalidOperationException($\"Setter is missing Property (value={setter.Value}).\");","typeGuard":"static bool HasProperty(Setter s) => s.Property is not null;","tryCatchPattern":null,"preventionTips":["Prefer the Setter(property, value) constructor to force setting Property.","Lint AXAML for `<Setter>` elements missing the Property attribute.","Validate Setters collection before attaching a style."],"tags":["avalonia","styling","setter","property","validation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}