{"record":{"id":"0b85271ff076aaa3","repo":"AvaloniaUI/Avalonia","slug":"dictionary","errorCode":null,"errorMessage":"dictionary","messagePattern":"dictionary","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Collections/AvaloniaDictionary.cs","lineNumber":48,"sourceCode":"        /// Initializes a new instance of the <see cref=\"AvaloniaDictionary{TKey, TValue}\"/> class.\n        /// </summary>\n        public AvaloniaDictionary(int capacity)\n        {\n            _inner = new Dictionary<TKey, TValue>(capacity);\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"AvaloniaDictionary{TKey, TValue}\"/> class using an IDictionary.\n        /// </summary>\n        public AvaloniaDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey>? comparer = null)\n        {\n            if (dictionary != null)\n            {\n                _inner = new Dictionary<TKey, TValue>(dictionary, comparer ?? EqualityComparer<TKey>.Default);\n            }\n            else\n            {\n                throw new ArgumentNullException(nameof(dictionary));\n            }\n        }\n\n        /// <summary>\n        /// Occurs when the collection changes.\n        /// </summary>\n        public event NotifyCollectionChangedEventHandler? CollectionChanged;\n\n        /// <summary>\n        /// Raised when a property on the collection changes.\n        /// </summary>\n        public event PropertyChangedEventHandler? PropertyChanged;\n\n        /// <inheritdoc cref=\"ICollection{T}.Count\"/>\n        public int Count => _inner.Count;\n\n        /// <inheritdoc cref=\"ICollection{T}.IsReadOnly\"/>\n        public bool IsReadOnly => false;","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Collections/AvaloniaDictionary.cs#L30-L66","documentation":"ArgumentNullException thrown by the AvaloniaDictionary copy constructor when the source IDictionary is null. The constructor needs a non-null source dictionary to seed its inner Dictionary.","triggerScenarios":"Calling 'new AvaloniaDictionary<TKey,TValue>(null)' or passing a null reference from a variable/expression to the dictionary constructor overload that accepts IDictionary<TKey,TValue>.","commonSituations":"A factory or mapper method that receives an optional/null source collection and forwards it without a null check; deserialization or initialization where the source map has not been populated yet.","solutions":["Pass a non-null source dictionary, or use the parameterless constructor when you have no source.","Null-check the source before constructing: 'new AvaloniaDictionary<TKey,TValue>(src ?? new Dictionary<TKey,TValue>())'.","Coalesce upstream so the caller never hands null to the constructor."],"exampleFix":"// before\nvar dict = new AvaloniaDictionary<string,int>(maybeNull);\n\n// after\nvar dict = maybeNull is null\n    ? new AvaloniaDictionary<string,int>()\n    : new AvaloniaDictionary<string,int>(maybeNull);","handlingStrategy":"validation","validationCode":"if (source is null) throw new ArgumentNullException(nameof(source));\nvar dict = new AvaloniaDictionary<TKey,TValue>(source);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Null-check source dictionaries before constructing.","Use the parameterless constructor when no source exists.","Avoid forwarding optional nulls into the copy constructor."],"tags":["avalonia","collections","dictionary","null-argument"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}