{"record":{"id":"2415023d32d59d1b","repo":"PrismLibrary/Prism","slug":"key","errorCode":null,"errorMessage":"key","messagePattern":"key","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Prism.Core/Common/ListDictionary.cs","lineNumber":21,"sourceCode":"    /// <summary>\n    /// A dictionary of lists.\n    /// </summary>\n    /// <typeparam name=\"TKey\">The key to use for lists.</typeparam>\n    /// <typeparam name=\"TValue\">The type of the value held by lists.</typeparam>\n    public sealed class ListDictionary<TKey, TValue> : IDictionary<TKey, IList<TValue>>\n    {\n        readonly Dictionary<TKey, IList<TValue>> innerValues = [];\n\n        #region Public Methods\n\n        /// <summary>\n        /// If a list does not already exist, it will be created automatically.\n        /// </summary>\n        /// <param name=\"key\">The key of the list that will hold the value.</param>\n        public void Add(TKey key)\n        {\n            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","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Core/Common/ListDictionary.cs#L3-L39","documentation":"A generic validation guard in ListDictionary<TKey,TValue>.Add(TKey): the dictionary cannot create or look up a list without a key, so a null key argument throws ArgumentNullException naming 'key'. The input at fault is the null key passed to Add.","triggerScenarios":"Calling ListDictionary.Add(null) directly, or indirectly when an upstream producer inserts events/handlers keyed by a null key.","commonSituations":"Event aggregation registration code where a topic/type key variable was never initialized.","solutions":["Ensure the key variable is initialized before calling Add","Add a null check/guard at the call site"],"exampleFix":"// before\nlistDictionary.Add(topic);\n// after\nif (topic == null) throw new InvalidOperationException(\"Topic must be set\");\nlistDictionary.Add(topic);","handlingStrategy":"validation","validationCode":"if (key == null) throw new InvalidOperationException(\"key must be non-null before ListDictionary.Add\");","typeGuard":"static bool ValidKey<TKey>(TKey key) => key != null;","tryCatchPattern":"try { dict.Add(key); }\ncatch (ArgumentNullException) { /* log and skip null key */ }","preventionTips":["Never call Add with an uninitialized key variable","Validate keys at the API boundary before inserting","Treat null keys as caller bugs — they are rejected by ListDictionary"],"tags":["prism","listdictionary","argumentnull","dictionary-key"],"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"}