dotnet/wpf · error · ArgumentException

throw new…

Error message

throw new ArgumentException(SR.Format(SR.FrugalMap_TargetMapCannotHoldAllData, this.ToString(), newMap.ToString()), nameof(newMap));

What it means

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.

Solutions

  1. Ensure any custom FrugalMap store returns the correct FrugalListStoreState from InsertEntry (Success when the entry was inserted)
  2. Promote only to a strictly larger store type in the canonical order: SingleItem -> ThreeItem -> SixItem -> Array
  3. Update .NET/WPF — map promotion bugs have been patched in servicing releases
  4. If hit inside WPF, file a repro at github.com/dotnet/wpf; the caller cannot pass a different newMap through public APIs

Example fix

// before (custom store)
public override FrugalListStoreState InsertEntry(int key, object value)
{
    return FrugalListStoreState.ThreeItemList; // wrong: signals promotion need spuriously
}
// after
public override FrugalListStoreState InsertEntry(int key, object value)
{
    _entries[key] = value;
    return FrugalListStoreState.Success; // entry stored successfully
}
Defensive patterns

Strategy: try-catch

Validate before calling

// only actionable for custom store authors
if (newMap.InsertEntry(key, value) != FrugalMapStoreState.Success)
    throw new ArgumentException("Target store cannot hold the entry", nameof(newMap));

Try / catch

try
{
    loneStore.Promote(newMap);
}
catch (ArgumentException ex) when (ex.ParamName == "newMap")
{
    // target store too small: promote into the next larger store type instead
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/49a14008373ad72c. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalMap.cs:189

        }
        
        public override void Iterate(ArrayList list, FrugalMapIterationCallback callback)
        {
            if (Count == 1)
            {
                callback(list, _loneEntry.Key, _loneEntry.Value);
            }
        }

        public override void Promote(FrugalMapBase newMap)
        {
            if (FrugalMapStoreState.Success == newMap.InsertEntry(_loneEntry.Key, _loneEntry.Value))
            {
            }
            else
            {
                // newMap is smaller than previous map
                throw new ArgumentException(SR.Format(SR.FrugalMap_TargetMapCannotHoldAllData, this.ToString(), newMap.ToString()), nameof(newMap));
            }
        }

        // Size of this data store
        public override int Count
        {
            get
            {
                if (INVALIDKEY != _loneEntry.Key)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
        }

View on GitHub (pinned to 81131a70a4)