{"record":{"id":"a544e0f84f5aff68","repo":"RicoSuter/NSwag","slug":"key","errorCode":null,"errorMessage":"key","messagePattern":"key","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Core/Collections/ObservableDictionary.cs","lineNumber":217,"sourceCode":"        public ICollection<TKey> Keys => _dictionary.Keys;\n\n        internal Dictionary<TKey, TValue>.KeyCollection KeyCollection => _dictionary.Keys;\n\n        ICollection IDictionary.Values => _dictionary.Values;\n\n        ICollection IDictionary.Keys => _dictionary.Keys;\n\n        IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => Values;\n\n        /// <summary>Removes the specified key.</summary>\n        /// <param name=\"key\">The key.</param>\n        /// <returns></returns>\n        /// <exception cref=\"System.ArgumentNullException\">key</exception>\n        public virtual bool Remove(TKey key)\n        {\n            if (key == null)\n            {\n                throw new ArgumentNullException(nameof(key));\n            }\n\n            var removed = _dictionary.Remove(key);\n            if (removed)\n            {\n                OnCollectionChanged();\n            }\n            //OnCollectionChanged(NotifyCollectionChangedAction.Remove, new KeyValuePair<TKey, TValue>(key, value));\n            return removed;\n        }\n\n        /// <summary>Tries the get value.</summary>\n        /// <param name=\"key\">The key.</param>\n        /// <param name=\"value\">The value.</param>\n        /// <returns></returns>\n        public bool TryGetValue(TKey key, out TValue value)\n        {\n            return _dictionary.TryGetValue(key, out value);","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Core/Collections/ObservableDictionary.cs#L199-L235","documentation":"ObservableDictionary.Remove throws ArgumentNullException when the key argument is null. Null is never a valid dictionary key here, so the method fails fast before attempting the underlying Dictionary.Remove and collection-change notification.","triggerScenarios":"Calling Remove(null) on an ObservableDictionary, e.g. removing a schema or parameter keyed by a variable that was never assigned.","commonSituations":"Removing an OpenAPI component by a name that came from optional config or a failed lookup that returned null.","solutions":["Ensure the key variable is non-null before calling Remove","Check ContainsKey with a non-null key first; skip removal if null","Use an early return: if (key == null) return false;"],"exampleFix":"// before\ndict.Remove(key);\n// after\nif (key != null && dict.ContainsKey(key))\n{\n    dict.Remove(key);\n}","handlingStrategy":"validation","validationCode":"if (key != null) dict.Remove(key);","typeGuard":"bool canRemove = key is not null;","tryCatchPattern":null,"preventionTips":["Never store null as a candidate key; use string.Empty or a sentinel instead","Check ContainsKey before removal to avoid no-op or null keys"],"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"}