{"record":{"id":"ec216d06ec8586d4","repo":"PrismLibrary/Prism","slug":"value","errorCode":null,"errorMessage":"value","messagePattern":"value","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Prism.Core/Common/ListDictionary.cs","lineNumber":38,"sourceCode":"            if (key == null)\n                throw new ArgumentNullException(nameof(key));\n\n            CreateNewList(key);\n        }\n\n        /// <summary>\n        /// Adds a value to a list with the given key. If a list does not already exist,\n        /// it will be created automatically.\n        /// </summary>\n        /// <param name=\"key\">The key of the list that will hold the value.</param>\n        /// <param name=\"value\">The value to add to the list under the given key.</param>\n        public void Add(TKey key, TValue value)\n        {\n            if (key == null)\n                throw new ArgumentNullException(nameof(key));\n\n            if (value == null)\n                throw new ArgumentNullException(nameof(value));\n\n            if (innerValues.ContainsKey(key))\n            {\n                innerValues[key].Add(value);\n            }\n            else\n            {\n                List<TValue> values = CreateNewList(key);\n                values.Add(value);\n            }\n        }\n\n        private List<TValue> CreateNewList(TKey key)\n        {\n            List<TValue> values = new List<TValue>();\n            innerValues.Add(key, values);\n\n            return values;","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Core/Common/ListDictionary.cs#L20-L56","documentation":"A validation guard in ListDictionary<TKey,TValue>.Add(TKey,TValue): a null value argument is rejected with ArgumentNullException naming 'value', because storing null values under a key would corrupt the list-of-values semantics the dictionary guarantees. The input at fault is the null value passed to Add.","triggerScenarios":"Calling Add(validKey, null), often when a delegate/handler variable is null because subscription failed or the target was collected.","commonSituations":"Event aggregator style code registering a null handler reference, or lambdas assigned conditionally that ended up null.","solutions":["Ensure the value (e.g. handler delegate) is created before Add","Skip the Add call when the value is null"],"exampleFix":"// before\nlistDictionary.Add(key, handler);\n// after\nif (handler != null) listDictionary.Add(key, handler);","handlingStrategy":"validation","validationCode":"if (value == null) throw new InvalidOperationException(\"value must be non-null before ListDictionary.Add\");","typeGuard":"static bool ValidValue<TValue>(TValue v) => v != null;","tryCatchPattern":"try { dict.Add(key, handler); }\ncatch (ArgumentNullException) when (handler == null) { /* handler never initialized */ }","preventionTips":["Create the delegate/handler before registration","Skip or log when a handler is null instead of adding","Initialize handler fields at construction time"],"tags":["prism","listdictionary","argumentnull","null-value"],"backgroundTag":"null-argument","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}