{"record":{"id":"6840874fdc09db87","repo":"RicoSuter/NSwag","slug":"items","errorCode":null,"errorMessage":"items","messagePattern":"items","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Core/Collections/ObservableDictionary.cs","lineNumber":76,"sourceCode":"\n        /// <summary>Initializes a new instance of the <see cref=\"ObservableDictionary{TKey, TValue}\"/> class. </summary>\n        /// <param name=\"capacity\">The capacity. </param>\n        /// <param name=\"comparer\">The comparer. </param>\n        public ObservableDictionary(int capacity, IEqualityComparer<TKey> comparer)\n        {\n            _dictionary = new Dictionary<TKey, TValue>(capacity, comparer);\n        }\n\n        /// <summary>Gets the underlying dictonary. </summary>\n        protected Dictionary<TKey, TValue> Dictionary => _dictionary;\n\n        /// <summary>Adds multiple key-value pairs the the dictionary. </summary>\n        /// <param name=\"items\">The key-value pairs. </param>\n        public void AddRange(IDictionary<TKey, TValue> items)\n        {\n            if (items == null)\n            {\n                throw new ArgumentNullException(nameof(items));\n            }\n\n            if (items.Count > 0)\n            {\n                if (_dictionary.Count > 0)\n                {\n                    if (items.Keys.Any(k => _dictionary.ContainsKey(k)))\n                    {\n                        throw new ArgumentException(\"An item with the same key has already been added.\");\n                    }\n\n                    foreach (var pair in items)\n                    {\n                        _dictionary.Add(pair.Key, pair.Value);\n                    }\n                }\n                else\n                {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Core/Collections/ObservableDictionary.cs#L58-L94","documentation":"ObservableDictionary.AddRange throws ArgumentNullException when the items dictionary passed in is null. The method requires a non-null IDictionary<TKey,TValue> because it iterates and inspects the items count and keys immediately. This is a fail-fast guard so callers get a clear error at the call site instead of a NullReferenceException deeper in the add logic.","triggerScenarios":"Calling AddRange(null) on an ObservableDictionary, e.g. when building a dictionary from a nullable collection or a method that returned null.","commonSituations":"Populating OpenApiDocument extensions or parameters from a variable that was never initialized, or deserializing optional config that came back null and passing it straight to AddRange.","solutions":["Ensure the source dictionary is initialized before calling AddRange","Coalesce null to an empty dictionary with ?? new Dictionary<TKey,TValue>()","Guard with an if (items != null) check before calling AddRange"],"exampleFix":"// before\ndict.AddRange(externalItems);\n// after\nif (externalItems != null)\n{\n    dict.AddRange(externalItems);\n}","handlingStrategy":"validation","validationCode":"if (items == null) throw new ArgumentNullException(nameof(items)); // or skip the call\ndict.AddRange(items);","typeGuard":"bool canAddRange = items != null;","tryCatchPattern":"try { dict.AddRange(items); } catch (ArgumentNullException) { /* initialize items */ }","preventionTips":["Initialize dictionaries at declaration, never leave them null","Use ?? new Dictionary<TKey,TValue>() when sourcing from nullable APIs"],"tags":["nswag","null-argument","dictionary"],"backgroundTag":"null-argument","analyzedSha":"63daf8fcc3a25151b62eb4b326a1e8ea048a0d41","analyzedAt":"2026-09-14T11:38:15.205Z","contentChangedAt":"2026-09-14T11:38:15.205Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}