{"record":{"id":"e0f87d4d8f99df5f","repo":"dotnet/wpf","slug":"sr-format-sr-defaultvalueinvalid-propertyname","errorCode":null,"errorMessage":"SR.Format(SR.DefaultValueInvalid, propertyName)","messagePattern":"SR\\.Format\\(SR\\.DefaultValueInvalid, propertyName\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyProperty.cs","lineNumber":434,"sourceCode":"                        valueAsISealable.Seal();\n\n                        Invariant.Assert(dispatcherObject.Dispatcher == null,\n                            \"ISealable.Seal() failed after ISealable.CanSeal returned true\");\n                    }\n                    else\n                    {\n                        throw new ArgumentException(SR.Format(SR.DefaultValueMustBeFreeThreaded, propertyName));\n                    }\n                }\n            }\n\n\n            // After checking for correct type, check default value against\n            //  validator (when one is given)\n            if ( validateValueCallback != null &&\n                !validateValueCallback(defaultValue))\n            {\n                throw new ArgumentException(SR.Format(SR.DefaultValueInvalid, propertyName));\n            }\n        }\n\n\n        /// <summary>\n        ///     Parameter validation for OverrideMetadata, includes code to force\n        /// all base classes of \"forType\" to register their metadata so we know\n        /// what we are overriding.\n        /// </summary>\n        private void SetupOverrideMetadata(\n                Type forType,\n                PropertyMetadata typeMetadata,\n            out DependencyObjectType dType,\n            out PropertyMetadata baseMetadata )\n        {\n            ArgumentNullException.ThrowIfNull(forType);\n            ArgumentNullException.ThrowIfNull(typeMetadata);\n","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyProperty.cs#L416-L452","documentation":"When PropertyMetadata supplies a default value and the registration/override also has a validateValueCallback, WPF validates the default too. If the callback rejects the default value, ValidateDefaultValueCommon throws DefaultValueInvalid. The default must itself be a value the property would accept.","triggerScenarios":"Register(typeof(X), ..., new PropertyMetadata(0), v => (int)v > 0) — the default 0 fails the validator; similarly OverrideMetadata with a default that fails the inherited or supplied validator.","commonSituations":"Validators encoding business constraints (positive, non-empty, within range) combined with a naive type default like 0 or null.","solutions":["Change the metadata default to a value that passes the validator.","Adjust the validator to accept the type default if it is a legitimate initial state.","Use ValidateValueCallback only for invariants and CoerceValueCallback for business ranges."],"exampleFix":"// before\nnew PropertyMetadata(0), v => (int)v > 0\n// after\nnew PropertyMetadata(1), v => (int)v > 0","handlingStrategy":"validation","validationCode":"if (validator != null && !validator(defaultValue)) throw new ArgumentException(\"Default value fails validator\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run your validator against the metadata default during development/tests","Pick defaults that satisfy the validator, or move business constraints to coercion"],"tags":["wpf","dependency-property","validation"],"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-21T21:30:21.729Z"}