dotnet/wpf · error · ArgumentException
SR.Format(SR.InvalidPropertyValue, value…
Error message
SR.Format(SR.InvalidPropertyValue, value, dependencyProperty.Name)
What it means
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.
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.
Example fix
<!-- before --> <Setter Property="FontSize" Value="abc"/> <!-- after --> <Setter Property="FontSize" Value="14"/>
Defensive patterns
Strategy: validation
Validate before calling
if (!dp.IsValidValue(value) && !(value is MarkupExtension || value is DeferredReference))
throw new ArgumentException($"Invalid value for {dp.Name}"); Type guard
static bool IsValidFor(DependencyProperty dp, object v) => dp.IsValidValue(v) || v is MarkupExtension || v is DeferredReference;
Try / catch
try { LoadTemplateContent(); } catch (ArgumentException ex) { Log(ex.Message); /* fix XAML */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Bracket characters cannot be alpha-numeric or whitespace.
- Bracket characters cannot be one of the following: '=' …
- NotImplementedException
- Opening bracket character cannot be the same as closing…
- SR.Format(SR.DefaultValueInvalid, propertyName)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d98427360c5a1c15.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkTemplate.cs:835
ConverterParameter = templateBindingExtension.ConverterParameter
};
value = binding;
}
else
{
Debug.Fail("We do not have support for DynamicResource within unshared template content");
}
}
bool isMarkupExtension = value is MarkupExtension;
// Value needs to be valid for the DP, or Binding/MultiBinding/PriorityBinding/TemplateBinding.
if (!dependencyProperty.IsValidValue(value))
{
if (!isMarkupExtension && !(value is DeferredReference))
{
throw new ArgumentException(SR.Format(SR.InvalidPropertyValue, value, dependencyProperty.Name));
}
}
parentTemplateValues[dependencyProperty] = value;
dependencyObject.ProvideSelfAsInheritanceContext(value, dependencyProperty);
EffectiveValueEntry entry = new EffectiveValueEntry(dependencyProperty)
{
BaseValueSourceInternal = BaseValueSourceInternal.ParentTemplate,
Value = value
};
if (isMarkupExtension)
{
// entry will be updated to hold the value
StyleHelper.GetInstanceValue(
StyleHelper.TemplateDataField,View on GitHub (pinned to 81131a70a4)