dotnet/wpf · error · ArgumentNullException

throw new ArgumentNullException(nameof(list));

Error message

throw new ArgumentNullException(nameof(list));

What it means

FrugalMap.Iterate validates its arguments and throws ArgumentNullException when the list parameter is null (and separately when callback is null), since both are required to collect the iterated entries.

Solutions

  1. Always pass a non-null ArrayList instance to Iterate
  2. Also ensure the callback delegate is non-null
  3. Validate arguments at the wrapper boundary before delegating

Example fix

// before
map.Iterate(null, myCallback); // ArgumentNullException
// after
map.Iterate(new ArrayList(), myCallback);
Defensive patterns

Strategy: validation

Validate before calling

if (list == null) throw new ArgumentNullException(nameof(list));
if (callback == null) throw new ArgumentNullException(nameof(callback));

Type guard

bool CanIterate(ArrayList list, FrugalMapIterationCallback cb) => list != null && cb != null;

Try / catch

try { map.Iterate(list, cb); } catch (ArgumentNullException ex) when (ex.ParamName is "list" or "callback") { /* supply required args and retry */ }

Prevention

When it happens

Trigger: Calling FrugalMap.Iterate(null, callback) — the destination ArrayList is mandatory even if you only care about side effects of the callback.

Common situations: Utility wrappers that forward an uninitialized collection; refactoring where the list was made optional by the caller but remains required by the API.

Related errors


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

Appendix: source

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

                _mapStore.GetKeyValuePair(index, out key, out value);
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }
        }
        
        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;
            }

View on GitHub (pinned to 81131a70a4)