{"record":{"id":"d98427360c5a1c15","repo":"dotnet/wpf","slug":"sr-format-sr-invalidpropertyvalue-value-dependencyproperty","errorCode":null,"errorMessage":"SR.Format(SR.InvalidPropertyValue, value, dependencyProperty.Name)","messagePattern":"SR\\.Format\\(SR\\.InvalidPropertyValue, value, dependencyProperty\\.Name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkTemplate.cs","lineNumber":835,"sourceCode":"                        ConverterParameter = templateBindingExtension.ConverterParameter\n                    };\n\n                    value = binding;\n\n                }\n                else\n                {\n                    Debug.Fail(\"We do not have support for DynamicResource within unshared template content\");\n                }\n            }\n\n            bool isMarkupExtension = value is MarkupExtension;\n            // Value needs to be valid for the DP, or Binding/MultiBinding/PriorityBinding/TemplateBinding.\n            if (!dependencyProperty.IsValidValue(value))\n            {\n                if (!isMarkupExtension && !(value is DeferredReference))\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidPropertyValue, value, dependencyProperty.Name));\n                }\n            }\n\n            parentTemplateValues[dependencyProperty] = value;\n\n            dependencyObject.ProvideSelfAsInheritanceContext(value, dependencyProperty);\n\n            EffectiveValueEntry entry = new EffectiveValueEntry(dependencyProperty)\n            {\n                BaseValueSourceInternal = BaseValueSourceInternal.ParentTemplate,\n                Value = value\n            };\n\n            if (isMarkupExtension)\n            {\n                // entry will be updated to hold the value\n                StyleHelper.GetInstanceValue(\n                            StyleHelper.TemplateDataField,","sourceCodeStart":817,"sourceCodeEnd":853,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkTemplate.cs#L817-L853","documentation":"During LoadOptimizedTemplateContent, ReceivePropertySet validates that a value read for a dependency property is acceptable via DependencyProperty.IsValidValue. If the value is neither valid for the property nor a MarkupExtension/DeferredReference (binding-style value), an ArgumentException is thrown. This protects against templates assigning out-of-range or wrong-typed values to dependency properties.","triggerScenarios":"A compiled template's optimized content sets a dependency property to a value that fails IsValidValue (wrong type or outside validation, e.g. a negative value on a property with a validation callback) and the value is not a Binding/TemplateBinding/MarkupExtension/deferred reference.","commonSituations":"XAML in a template supplying an invalid attribute value (bad enum string, wrong unit, mismatched type); resource/dispatch issues where a StaticResource resolves to an invalid value at template load; tooling-generated XAML with type errors.","solutions":["Fix the value in the template XAML so it is valid for the dependency property (correct type/range/enum).","Use a Binding/TemplateBinding or MarkupExtension if the value must be computed dynamically.","Check the dependency property's metadata ValidateValueCallback for constraints and satisfy them."],"exampleFix":"<!-- before -->\n<Setter Property=\"FontSize\" Value=\"abc\"/>\n<!-- after -->\n<Setter Property=\"FontSize\" Value=\"14\"/>","handlingStrategy":"validation","validationCode":"if (!dp.IsValidValue(value) && !(value is MarkupExtension || value is DeferredReference))\n    throw new ArgumentException($\"Invalid value for {dp.Name}\");","typeGuard":"static bool IsValidFor(DependencyProperty dp, object v) => dp.IsValidValue(v) || v is MarkupExtension || v is DeferredReference;","tryCatchPattern":"try { LoadTemplateContent(); } catch (ArgumentException ex) { Log(ex.Message); /* fix XAML */ }","preventionTips":["Validate template attribute values against the dependency property's type and validation callback.","Prefer compiled/typed XAML tooling that catches these at build time.","Use bindings or markup extensions for dynamically computed values."],"tags":["wpf","dependency-property","validation","xaml"],"backgroundTag":"invalid-argument-value","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"}