{"record":{"id":"e000bf933dd7a8e0","repo":"AvaloniaUI/Avalonia","slug":"value-is-not-a-valid-value-for-property-name","errorCode":null,"errorMessage":"{value} is not a valid value for '{property.Name}'.","messagePattern":"(.+?) is not a valid value for '(.+?)'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/PropertyStore/ValueStore.cs","lineNumber":204,"sourceCode":"            observer.Start(source);\n            return observer;\n        }\n\n        public void ClearValue(AvaloniaProperty property)\n        {\n            if (TryGetEffectiveValue(property, out var effective) &&\n                (effective.Priority == BindingPriority.LocalValue || effective.IsOverridenCurrentValue))\n            {\n                effective.IsOverridenCurrentValue = false;\n                ReevaluateEffectiveValue(property, effective, ignoreLocalValue: true);\n            }\n        }\n\n        public IDisposable? SetValue<T>(StyledProperty<T> property, T value, BindingPriority priority)\n        {\n            if (property.ValidateValue?.Invoke(value) == false)\n            {\n                throw new ArgumentException($\"{value} is not a valid value for '{property.Name}'.\");\n            }\n\n            if (priority != BindingPriority.LocalValue)\n            {\n                var frame = GetOrCreateImmediateValueFrame(property, priority, out _);\n                var result = frame.AddValue(property, value);\n\n                if (TryGetEffectiveValue(property, out var existing))\n                {\n                    var effective = (EffectiveValue<T>)existing;\n                    effective.SetAndRaise(this, result, priority);\n                }\n                else\n                {\n                    var effectiveValue = CreateEffectiveValue(property);\n                    AddEffectiveValue(property, effectiveValue);\n                    effectiveValue.SetAndRaise(this, result, priority);\n                }","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/PropertyStore/ValueStore.cs#L186-L222","documentation":"ValueStore.SetValue<T>(StyledProperty<T>, value, priority) runs the property's ValidateValue validation delegate before storing; if it returns false the value is rejected with ArgumentException. This is Avalonia's per-property validation gate for styled properties, enforcing value invariants (ranges, non-null, custom rules) independent of coercion.","triggerScenarios":"Calling SetValue / the property setter (or a binding) with a value that the StyledProperty's ValidateValue callback evaluates to false. Also reachable via AvaloniaObject.SetValue overloads that funnel into this method.","commonSituations":"Setting a numeric property outside its allowed range (e.g. Width < 0, opacity outside 0..1), assigning null to a non-null property, or assigning a value that violates a custom ValidateValue rule a control author added.","solutions":["Inspect the StyledProperty's ValidateValue delegate (or its XML doc / source) to learn the allowed value set and pass only valid values.","Clamp/coerce the value before assignment (e.g. Math.Max(0, value) for non-negative properties).","For bindings, add a validation/transform in the binding pipeline so invalid upstream values never reach SetValue.","If you own the property, widen ValidateValue or throw a more descriptive exception to aid debugging."],"exampleFix":"// before\ncontrol.Width = -5; // ValidateValue returns false -> ArgumentException\n\n// after\ncontrol.Width = Math.Max(0, width);","handlingStrategy":"validation","validationCode":"if (property.ValidateValue != null && !property.ValidateValue(value)) return;\ncontrol.SetValue(property, value);","typeGuard":"bool IsValid<T>(StyledProperty<T> p, T v) => p.ValidateValue is null || p.ValidateValue(v);","tryCatchPattern":"try { control.SetValue(property, value); }\ncatch (ArgumentException ex) { /* log invalid value, keep previous */ }","preventionTips":["Read the property's ValidateValue rule or XML doc before assigning.","Clamp numeric values (e.g. Math.Max(0, x)) before setting.","Validate in binding transforms so upstream bad values never reach SetValue.","Unit-test boundary values for custom styled properties."],"tags":["avalonia","styled-property","validation","value-store","argument"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}