{"record":{"id":"d55db936da13bc4f","repo":"dotnet/wpf","slug":"sr-format-sr-nullpropertyillegal-setter-property","errorCode":null,"errorMessage":"SR.Format(SR.NullPropertyIllegal, \"Setter.Property\")","messagePattern":"SR\\.Format\\(SR\\.NullPropertyIllegal, \"Setter\\.Property\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Setter.cs","lineNumber":90,"sourceCode":"                throw new InvalidOperationException(SR.Format(SR.CannotHavePropertyInStyle, FrameworkElement.NameProperty.Name));\n            }\n        }\n\n        /// <summary>\n        ///     Seals this setter\n        /// </summary>\n        internal override void Seal()\n        {\n\n            // Do the validation that can't be done until we know all of the property\n            // values.\n\n            DependencyProperty dp = Property;\n            object value = ValueInternal;\n\n            if (dp == null)\n            {\n                throw new ArgumentException(SR.Format(SR.NullPropertyIllegal, \"Setter.Property\"));\n            }\n\n            if( String.IsNullOrEmpty(TargetName))\n            {\n                // Setter on container is not allowed to affect the StyleProperty.\n                if (dp == FrameworkElement.StyleProperty)\n                {\n                    throw new ArgumentException(SR.StylePropertyInStyleNotAllowed);\n                }\n            }\n\n            // Value needs to be valid for the DP, or a deferred reference, or one of the supported\n            // markup extensions.\n\n            if (!dp.IsValidValue(value))\n            {\n                // The only markup extensions supported by styles is resources and bindings.\n                if (value is MarkupExtension)","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Setter.cs#L72-L108","documentation":"A Setter used inside a Style, ControlTemplate, or Trigger must declare which dependency property it sets. WPF throws this ArgumentException during Setter.Seal() because the Property property is null when the style is sealed. Styles are validated (sealed) when applied, so the failure surfaces when the style is used, not when the Setter object is constructed.","triggerScenarios":"A Setter element in XAML without a Property attribute, or a Setter created in code via `new Setter { Value = x }` without assigning Property, then the containing Style/Trigger is sealed (applied to an element).","commonSituations":"XAML typo like `<Setter Value=\"Red\"/>` missing `Property=\"Background\"`; dynamically building styles in code and forgetting to set the Property; data-bound styles built at runtime.","solutions":["Add the Property attribute to every Setter: `<Setter Property=\"Background\" Value=\"Red\"/>`.","In code, set setter.Property = SomeUIElement.SomeProperty before adding it to a style or applying the style.","Validate all setters programmatically before applying the style: foreach (SetterBase s in style.Setters) if (s is Setter st && st.Property == null) throw/log."],"exampleFix":"// before\nvar s = new Setter { Value = Brushes.Red };\nstyle.Setters.Add(s);\n// after\nvar s = new Setter { Property = Control.BackgroundProperty, Value = Brushes.Red };\nstyle.Setters.Add(s);","handlingStrategy":"validation","validationCode":"foreach (var s in style.Setters.OfType<Setter>())\n    if (s.Property == null) throw new InvalidOperationException(\"Setter missing Property\");","typeGuard":"bool HasProperty(Setter s) => s.Property != null;","tryCatchPattern":"try { element.Style = style; }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Setter.Property\")) { /* log and fix style */ }","preventionTips":["Always specify Property on every Setter element in XAML","When building styles in code, set Property in the object initializer"],"tags":["wpf","xaml","style","setter"],"backgroundTag":"missing-required-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}