{"record":{"id":"8b5fc2122eb17023","repo":"dotnet/wpf","slug":"sr-format-sr-toomanydependencyproperties-ownertype-name-name","errorCode":null,"errorMessage":"SR.Format(SR.TooManyDependencyProperties, ownerType.Name + \".\" + name)","messagePattern":"SR\\.Format\\(SR\\.TooManyDependencyProperties, ownerType\\.Name \\+ \"\\.\" \\+ name\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyProperty.cs","lineNumber":1100,"sourceCode":"            {\n                packedData |= Flags.IsStringType;\n            }\n\n            _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","sourceCodeStart":1082,"sourceCodeEnd":1118,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyProperty.cs#L1082-L1118","documentation":"GetUniqueGlobalIndex throws this InvalidOperationException when GlobalIndexCount reaches the limit of GlobalIndexMask (15 bits, ~32767), meaning more dependency properties have been registered than the per-process global index can represent. The message includes ownerType.name for the property that pushed the count over the limit.","triggerScenarios":"Registering more than GlobalIndexMask dependency properties in one AppDomain — e.g. dynamic registration in a loop (Register/AddOwner) or an extremely large number of libraries/static DPs.","commonSituations":"Apps or plugin hosts that register DPs per data column or per config item in unbounded loops; massive dynamic code generation frameworks creating a DP per schema field; long-running plugin systems accumulating registrations.","solutions":["Stop registering DPs dynamically in loops; register a fixed set of DPs and store per-item data in regular CLR properties, attached-object dictionaries, or Freezable instances","Replace per-column DPs with a single attached property plus a value lookup keyed by column id","Recycle/reuse already-registered DPs instead of minting new ones per entity type"],"exampleFix":"// before\nforeach (var col in schema.Columns)\n    cols.Add(DependencyProperty.Register(col.Name, typeof(object), typeof(Row))); // unbounded\n// after\npublic static readonly DependencyProperty ValueProperty =\n    DependencyProperty.Register(\"Value\", typeof(object), typeof(Row));\n// one DP; per-column values kept in Row's own dictionary keyed by column","handlingStrategy":"validation","validationCode":"// bounded registration check before minting DPs in bulk\nif (registeredDpCount + newCount > 32000)\n    throw new InvalidOperationException(\"Approaching DependencyProperty global index limit\");","typeGuard":null,"tryCatchPattern":"try { var dp = DependencyProperty.Register(name, typeof(object), ownerType); }\ncatch (InvalidOperationException) { /* index exhausted: switch to attached property / dictionary storage */ }","preventionTips":["Never register DPs in unbounded loops or per data item","Use a fixed set of DPs plus per-item storage (dictionary, attached object)","Keep total DP registrations in the hundreds/thousands, not tens of thousands"],"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"}