{"record":{"id":"5c1e6e21f4486856","repo":"dotnet/wpf","slug":"sr-invalidpropertyvalue-dependencyobject","errorCode":null,"errorMessage":"SR.InvalidPropertyValue","messagePattern":"SR\\.InvalidPropertyValue","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObject.cs","lineNumber":326,"sourceCode":"            if (!entry.HasModifiers)\n            {\n                // For thread-safety, sealed DOs can't modify _effectiveValues.\n                Debug.Assert(!DO_Sealed, \"A Sealed DO cannot be modified\");\n\n                if (!entry.HasExpressionMarker)\n                {\n                    // The value for this property was meant to come from a dictionary\n                    // and the creation of that value had been deferred until this\n                    // time for better performance. Now is the time to actually instantiate\n                    // this value by querying it from the dictionary. Once we have the\n                    // value we can actually replace the deferred reference marker\n                    // with the actual value.\n                    DeferredReference reference = (DeferredReference)entry.Value;\n                    object value = reference.GetValue(entry.BaseValueSourceInternal);\n\n                    if (!dp.IsValidValue(value))\n                    {\n                        throw new InvalidOperationException(SR.Format(SR.InvalidPropertyValue, value, dp.Name));\n                    }\n\n                    // Make sure the entryIndex is in sync after\n                    // the inflation of the deferred reference.\n                    entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex);\n\n                    entry.Value = value;\n\n                    _effectiveValues[entryIndex.Index] = entry;\n                    return entry;\n                }\n            }\n            else\n            {\n                // The value for this property was meant to come from a dictionary\n                // and the creation of that value had been deferred until this\n                // time for better performance. Now is the time to actually instantiate\n                // this value by querying it from the dictionary. Once we have the","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObject.cs#L308-L344","documentation":"DependencyObject.GetEffectiveValue inflates a DeferredReference (a value kept on the WPF property system's deferred store, e.g. from a deferred resource or expression) into a real object. If the inflated value fails DependencyProperty.IsValidValue validation for that property, it throws InvalidOperationException(SR.InvalidPropertyValue, value, dp.Name) — the deferred value has the wrong type/value for the target property.","triggerScenarios":"Reading (GetValue) a dependency property whose stored value came from a deferred provider (style/resource dictionary deferred reference, deferred brush/image) and the deferred object doesn't match the property's type or validation, e.g. a string stored where a Double property expects a number with incompatible type conversion.","commonSituations":"Resource dictionaries with mistyped resources (a Color where a Brush is expected); cross-version assembly mismatch changing a property's type; theme/style values set through deferred content failing validation at first read.","solutions":["Fix the deferred value's source (resource/style/expression) so it produces the exact type the dependency property expects.","Check IsValidValue before reading: DependencyProperty.IsValidType / property metadata ValidateValueCallback on the candidate object.","Validate XAML resources at design/build time (e.g. enable resource type checks, run XAML compilation) to catch mismatched resource types."],"exampleFix":"<!-- before -->\n<Setter Property=\"FontSize\" Value=\"Red\" />\n<!-- after -->\n<Setter Property=\"FontSize\" Value=\"12\" />","handlingStrategy":"validation","validationCode":"object v = deferredValue;\nif (dp != null && !dp.IsValidType(v?.GetType() ?? typeof(object)))\n    throw new InvalidOperationException($\"Value {v} of type {v?.GetType()} is invalid for property {dp.Name}\");","typeGuard":"bool IsValidForProperty(DependencyProperty dp, object value) =>\n    value == DependencyProperty.UnsetValue || dp.IsValidType(value.GetType());","tryCatchPattern":"try { var value = target.GetValue(MyProperty); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"InvalidPropertyValue\") || ex.Message.Contains(MyProperty.Name))\n{\n    target.SetValue(MyProperty, fallbackValue); // recover with a known-good value\n}","preventionTips":["Ensure resource/style values match the DP's PropertyType exactly.","Run XAML compilation/resource audits to catch mistyped resources.","Check dp.IsValidType on deferred/dynamic values before assigning or reading."],"tags":["wpf","dependency-property","type-mismatch","deferred-value"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}