{"record":{"id":"8e1a2f2230d4e066","repo":"dotnet/wpf","slug":"sr-format-sr-frugallist-targetmapcannotholdalldata-oldlist","errorCode":null,"errorMessage":"SR.Format(SR.FrugalList_TargetMapCannotHoldAllData, oldList.ToString(), this.ToString())","messagePattern":"SR\\.Format\\(SR\\.FrugalList_TargetMapCannotHoldAllData, oldList\\.ToString\\(\\), this\\.ToString\\(\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalList.cs","lineNumber":331,"sourceCode":"            --_count;\n        }\n\n        public override T EntryAt(int index)\n        {\n            return _loneEntry;\n        }\n\n        public override void Promote(FrugalListBase<T> oldList)\n        {\n            if (oldList.Count == SIZE)\n            {\n                SetCount(SIZE);\n                SetAt(0, oldList.EntryAt(0));\n            }\n            else\n            {\n                // this list is smaller than oldList\n                throw new ArgumentException(SR.Format(SR.FrugalList_TargetMapCannotHoldAllData, oldList.ToString(), this.ToString()), nameof(oldList));\n            }\n        }\n\n        // Class specific implementation to avoid virtual method calls and additional logic\n        public void Promote(SingleItemList<T> oldList)\n        {\n            SetCount(oldList.Count);\n            SetAt(0, oldList.EntryAt(0));\n        }\n\n        public override T[] ToArray()\n        {\n            T[] array = new T[SIZE];\n            array[0] = _loneEntry;\n            return array;\n        }\n\n        public override void CopyTo(T[] array, int index)","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalList.cs#L313-L349","documentation":"FrugalList Promote throws ArgumentException (message resource FrugalList_TargetMapCannotHoldAllData) when promoting a smaller-capacity frugal list into a larger one that is itself already full — the target map cannot hold all the data from the old list. This is an internal capacity invariant violation discovered during list promotion (called from Clone).","triggerScenarios":"Clone (or Promote) is invoked to move a SingleItemList/ThreeItemList's contents into a larger frugal list whose current count plus the source count exceeds the target's fixed capacity — the target has no free slot for every old entry.","commonSituations":"Growth of frugal collections (used heavily by WPF dependency-property value stores) when many values are stored; a bug or corrupted count in the store can make the promotion target smaller than the source data.","solutions":["Promote to a capacity class at least large enough for oldList.Count plus existing target entries","Ensure Promote is only called on targets with sufficient remaining capacity — check _count before promoting","If hit through normal Add growth, this indicates an internal invariant bug; capture the list counts and file a WPF issue"],"exampleFix":"// before\nif (oldList.Count > SIZE) Promote(oldList); // target too small\n// after\nif (Count + oldList.Count <= SIZE) Promote(oldList);\nelse Promote(new LargerList(this));","handlingStrategy":"try-catch","validationCode":"if (target.Count + source.Count > target.Capacity) target = new LargerFrugalList(target);","typeGuard":null,"tryCatchPattern":"try { target.Promote(oldList); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"CannotHoldAllData\")) { /* promote to a larger capacity class instead */ }","preventionTips":["Always promote to a capacity class strictly larger than the source","Track counts so target has room for all incoming entries","Treat this throw as an internal invariant bug and report it"],"tags":["wpf","collections","capacity"],"backgroundTag":"internal-invariant-violation","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"}