{"record":{"id":"dc3648f65c8d6c98","repo":"dotnet/wpf","slug":"sr-format-sr-toomanydependencyproperties-constantproperty","errorCode":null,"errorMessage":"SR.Format(SR.TooManyDependencyProperties, \"ConstantProperty\")","messagePattern":"SR\\.Format\\(SR\\.TooManyDependencyProperties, \"ConstantProperty\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyProperty.cs","lineNumber":1104,"sourceCode":"            _packedData = packedData;\n        }\n\n        // Synchronized: Covered by DependencyProperty.Synchronized\n        internal static int GetUniqueGlobalIndex(Type ownerType, string name)\n        {\n            // Prevent GlobalIndex from overflow. DependencyProperties are meant to be static members and are to be registered\n            // only via static constructors. However there is no cheap way of ensuring this, without having to do a stack walk. Hence\n            // concievably people could register DependencyProperties via instance methods and therefore cause the GlobalIndex to\n            // overflow. This check will explicitly catch this error, instead of silently malfuntioning.\n            if (GlobalIndexCount >= (int)Flags.GlobalIndexMask)\n            {\n                if (ownerType != null)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.TooManyDependencyProperties, ownerType.Name + \".\" + name));\n                }\n                else\n                {\n                    throw new InvalidOperationException(SR.Format(SR.TooManyDependencyProperties, \"ConstantProperty\"));\n                }\n            }\n\n            // Covered by Synchronized by caller\n            return GlobalIndexCount++;\n        }\n\n        /// <summary>\n        /// This is the callback designers use to participate in the computation of property\n        /// values at design time. Eg. Even if the author sets Visibility to Hidden, the designer\n        /// wants to coerce the value to Visible at design time so that the element doesn't\n        /// disappear from the design surface.\n        /// </summary>\n        internal CoerceValueCallback DesignerCoerceValueCallback\n        {\n            get {  return _designerCoerceValueCallback; }\n            set\n            {","sourceCodeStart":1086,"sourceCodeEnd":1122,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyProperty.cs#L1086-L1122","documentation":"Same global-index overflow as the ownerType variant, but raised when ownerType is null — i.e. the overflow occurred while registering something without an owner type, reported with the placeholder name \"ConstantProperty\". GlobalIndexCount exceeded GlobalIndexMask, so no unique global index can be assigned.","triggerScenarios":"Exceeding ~32767 registered dependency properties in the AppDomain via a registration path that passes a null ownerType into GetUniqueGlobalIndex (internal constant/property registration paths).","commonSituations":"Same as the ownerType overflow: dynamic DP creation at scale, plugin systems, codegen frameworks; the null-owner variant usually indicates an internal registration path, so look at total DP counts in the process.","solutions":["Reduce total number of registered DPs in the process; audit libraries doing dynamic registration","Replace dynamic DP-per-item patterns with attached properties or plain dictionaries","Profile with a debugger/ETW to find who registers tens of thousands of DPs and fix that library"],"exampleFix":"// before\n// thousands of generated static types each Register-ing DPs at module load\nvar dp = DependencyProperty.Register(name, typeof(object), ownerType); // called in loop\n// after\nvar valueCache = new Dictionary<object, object>(); // plain storage\n// or a single attached property:\npublic static readonly DependencyProperty ValueProperty =\n    DependencyProperty.RegisterAttached(\"Value\", typeof(object), typeof(Holder));","handlingStrategy":"validation","validationCode":"// audit total DP registrations before adding more\nif (Interlocked.Increment(ref registeredDpCount) > 32000)\n    throw new InvalidOperationException(\"Global DP index exhausted\");","typeGuard":null,"tryCatchPattern":"try { RegisterInternally(name, value); }\ncatch (InvalidOperationException) { /* overflow: degrade to non-DP storage */ }","preventionTips":["Audit plugin libraries that register DPs at load time","Cap dynamic DP creation; use RegisterAttached once and key values yourself","Monitor DP counts in long-running hosts"],"tags":["wpf","dependency-property","global-index-limit","resource-exhaustion","invalid-operation"],"backgroundTag":"value-out-of-range","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"}