{"record":{"id":"1554ad2d885b3284","repo":"dotnet/wpf","slug":"throw-new-argumentnullexception-nameof-callback","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(callback));","messagePattern":"throw new ArgumentNullException\\(nameof\\(callback\\)\\);","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalMap.cs","lineNumber":1785,"sourceCode":"            }\n        }\n        \n        public void Iterate(ArrayList list, FrugalMapIterationCallback callback)\n        {\n            if (null != callback)\n            {\n                if (null != list)\n                {\n                    _mapStore?.Iterate(list, callback);\n                }\n                else\n                {\n                    throw new ArgumentNullException(nameof(list));\n                }\n            }\n            else\n            {\n                throw new ArgumentNullException(nameof(callback));\n            }\n        }\n\n        public int Count\n        {\n            get\n            {\n                if (null != _mapStore)\n                {\n                    return _mapStore.Count;\n                }\n                return 0;\n            }\n        }\n\n        internal FrugalMapBase _mapStore;\n    }\n","sourceCodeStart":1767,"sourceCodeEnd":1803,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalMap.cs#L1767-L1803","documentation":"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.","triggerScenarios":"Calling FrugalMap.Iterate (or the store's Iterate overload) passing null for the callback parameter while the list argument is valid.","commonSituations":"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.","solutions":["Create and pass a valid FrugalMapIterationCallback delegate","Check the callback for null before calling Iterate and return early or throw a descriptive error","If iterating an empty map, note callback null is still rejected when callback is the first-checked argument"],"exampleFix":"// before\nmap.Iterate(list, null);\n// after\nFrugalMapIterationCallback callback = (key, value) => Console.WriteLine($\"{key}={value}\");\nmap.Iterate(list, callback);","handlingStrategy":"validation","validationCode":"if (callback == null) throw new ArgumentNullException(nameof(callback));\nmap.Iterate(list, callback);","typeGuard":"bool IsValidCallback(FrugalMapIterationCallback cb) => cb is not null;","tryCatchPattern":"try { map.Iterate(list, callback); } catch (ArgumentNullException ex) when (ex.ParamName == \"callback\") { /* supply default callback */ }","preventionTips":["Never pass possibly-null delegates to Iterate","Null-check delegate fields before use","Default-initialize callbacks with no-op lambdas"],"tags":["csharp","wpf","null-argument"],"backgroundTag":"null-argument","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"}