{"record":{"id":"49a14008373ad72c","repo":"dotnet/wpf","slug":"throw-new-argumentexception-sr-format-sr-frugalmap","errorCode":null,"errorMessage":"throw new ArgumentException(SR.Format(SR.FrugalMap_TargetMapCannotHoldAllData, this.ToString(), newMap.ToString()), nameof(newMap));","messagePattern":"throw new ArgumentException\\(SR\\.Format\\(SR\\.FrugalMap_TargetMapCannotHoldAllData, this\\.ToString\\(\\), newMap\\.ToString\\(\\)\\), nameof\\(newMap\\)\\);","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalMap.cs","lineNumber":189,"sourceCode":"        }\n        \n        public override void Iterate(ArrayList list, FrugalMapIterationCallback callback)\n        {\n            if (Count == 1)\n            {\n                callback(list, _loneEntry.Key, _loneEntry.Value);\n            }\n        }\n\n        public override void Promote(FrugalMapBase newMap)\n        {\n            if (FrugalMapStoreState.Success == newMap.InsertEntry(_loneEntry.Key, _loneEntry.Value))\n            {\n            }\n            else\n            {\n                // newMap is smaller than previous map\n                throw new ArgumentException(SR.Format(SR.FrugalMap_TargetMapCannotHoldAllData, this.ToString(), newMap.ToString()), nameof(newMap));\n            }\n        }\n\n        // Size of this data store\n        public override int Count\n        {\n            get\n            {\n                if (INVALIDKEY != _loneEntry.Key)\n                {\n                    return 1;\n                }\n                else\n                {\n                    return 0;\n                }\n            }\n        }","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalMap.cs#L171-L207","documentation":"SingleItemList.Promote(newMap) moves the lone entry into a larger store when the FrugalMap grows. If newMap.InsertEntry reports anything but FrugalMapStoreState.Success, the target store is smaller or incompatible and the method throws ArgumentException(FrugalMap_TargetMapCannotHoldAllData, paramName: newMap). The argument name is newMap because the supplied destination cannot hold the source data.","triggerScenarios":"Promote called with a newMap whose store cannot accept the lone entry (InsertEntry returns Failure/known larger-state mismatch), i.e. promoting to a store type with equal or smaller capacity.","commonSituations":"Internal WPF property-value store growth (a second keyed value being added to an object's effective values), custom FrugalMap store subclasses that return the wrong FrugalListStoreState, or reflection-driven manipulation of the map's private store.","solutions":["Ensure any custom FrugalMap store returns the correct FrugalListStoreState from InsertEntry (Success when the entry was inserted)","Promote only to a strictly larger store type in the canonical order: SingleItem -> ThreeItem -> SixItem -> Array","Update .NET/WPF — map promotion bugs have been patched in servicing releases","If hit inside WPF, file a repro at github.com/dotnet/wpf; the caller cannot pass a different newMap through public APIs"],"exampleFix":"// before (custom store)\npublic override FrugalListStoreState InsertEntry(int key, object value)\n{\n    return FrugalListStoreState.ThreeItemList; // wrong: signals promotion need spuriously\n}\n// after\npublic override FrugalListStoreState InsertEntry(int key, object value)\n{\n    _entries[key] = value;\n    return FrugalListStoreState.Success; // entry stored successfully\n}","handlingStrategy":"try-catch","validationCode":"// only actionable for custom store authors\nif (newMap.InsertEntry(key, value) != FrugalMapStoreState.Success)\n    throw new ArgumentException(\"Target store cannot hold the entry\", nameof(newMap));","typeGuard":null,"tryCatchPattern":"try\n{\n    loneStore.Promote(newMap);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"newMap\")\n{\n    // target store too small: promote into the next larger store type instead\n}","preventionTips":["Custom FrugalMap stores must return FrugalMapStoreState.Success on successful insert and the correct larger-store state otherwise","Promote strictly upward: SingleItem -> ThreeItem -> SixItem -> Array","Never manipulate FrugalMap internals via reflection","Keep .NET/WPF updated; report framework-side occurrences to dotnet/wpf"],"tags":["wpf","frugal-map","argument-exception","promotion"],"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"}