dotnet/wpf · error · ArgumentNullException

throw new ArgumentNullException(nameof(callback));

Error message

throw new ArgumentNullException(nameof(callback));

What it means

FrugalMapIterationCallback-based Iterate validates its inputs before iterating. If the delegate 'callback' is null (and the store has data), FrugalMap throws ArgumentNullException because iterating requires a non-null callback to receive each key/value pair.

Solutions

  1. Create and pass a valid FrugalMapIterationCallback delegate
  2. Check the callback for null before calling Iterate and return early or throw a descriptive error
  3. If iterating an empty map, note callback null is still rejected when callback is the first-checked argument

Example fix

// before
map.Iterate(list, null);
// after
FrugalMapIterationCallback callback = (key, value) => Console.WriteLine($"{key}={value}");
map.Iterate(list, callback);
Defensive patterns

Strategy: validation

Validate before calling

if (callback == null) throw new ArgumentNullException(nameof(callback));
map.Iterate(list, callback);

Type guard

bool IsValidCallback(FrugalMapIterationCallback cb) => cb is not null;

Try / catch

try { map.Iterate(list, callback); } catch (ArgumentNullException ex) when (ex.ParamName == "callback") { /* supply default callback */ }

Prevention

When it happens

Trigger: Calling FrugalMap.Iterate (or the store's Iterate overload) passing null for the callback parameter while the list argument is valid.

Common situations: Forgetting to initialize a delegate field before passing it to Iterate; refactoring code so a callback-returning method now returns null; copying sample code that omitted callback creation.

Related errors


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

Appendix: source

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

            }
        }
        
        public void Iterate(ArrayList list, FrugalMapIterationCallback callback)
        {
            if (null != callback)
            {
                if (null != list)
                {
                    _mapStore?.Iterate(list, callback);
                }
                else
                {
                    throw new ArgumentNullException(nameof(list));
                }
            }
            else
            {
                throw new ArgumentNullException(nameof(callback));
            }
        }

        public int Count
        {
            get
            {
                if (null != _mapStore)
                {
                    return _mapStore.Count;
                }
                return 0;
            }
        }

        internal FrugalMapBase _mapStore;
    }

View on GitHub (pinned to 81131a70a4)