{"record":{"id":"afbb836aec88e78f","repo":"stride3d/stride","slug":"argumentnullexception","errorCode":null,"errorMessage":"ArgumentNullException","messagePattern":"ArgumentNullException","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/SortedDictionary.cs","lineNumber":510,"sourceCode":"                    if (NotStartedOrEnded)\n                    {\n                        throw new InvalidOperationException();\n                    }\n\n                    return new DictionaryEntry(Current.Key, Current.Value);\n                }\n            }\n        }\n\n        public sealed class KeyCollection : ICollection<TKey>, ICollection\n        {\n            private readonly SortedDictionary<TKey, TValue> dictionary;\n\n            public KeyCollection(SortedDictionary<TKey, TValue> dictionary)\n            {\n                if (dictionary == null)\n                {\n                    throw new ArgumentNullException();\n                }\n                this.dictionary = dictionary;\n            }\n\n            public Enumerator GetEnumerator()\n            {\n                return new Enumerator(dictionary);\n            }\n\n            IEnumerator<TKey> IEnumerable<TKey>.GetEnumerator()\n            {\n                return new Enumerator(dictionary);\n            }\n\n            IEnumerator IEnumerable.GetEnumerator()\n            {\n                return new Enumerator(dictionary);\n            }","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/SortedDictionary.cs#L492-L528","documentation":"The SortedDictionary.KeyCollection constructor throws ArgumentNullException (without a parameter name) when the dictionary argument is null. A key collection is a live view over a dictionary and cannot exist without one.","triggerScenarios":"Calling new dictionary.Keys-style construction is not user-facing, but any code path that builds a KeyCollection from a null SortedDictionary reference — usually a dictionary variable that was never initialized.","commonSituations":"A SortedDictionary field defaulting to null, then passing it into APIs that construct key collections.","solutions":["Initialize the SortedDictionary before accessing .Keys","Null-check the dictionary before using its KeyCollection","Wrap dictionary creation in the type's initialization logic"],"exampleFix":"// before\nSortedDictionary<string,int> dict;\nvar keys = new SortedDictionary<string,int>.KeyCollection(dict); // null\n// after\nvar dict = new SortedDictionary<string,int>();\nvar keys = dict.Keys;","handlingStrategy":"validation","validationCode":"if (dict == null) throw new InvalidOperationException(\"Dictionary must be initialized before accessing Keys\");","typeGuard":"TKey[] SafeKeys<TKey,TValue>(SortedDictionary<TKey,TValue> d) => d?.Keys?.ToArray();","tryCatchPattern":"try { var keys = new SortedDictionary<TKey,TValue>.KeyCollection(dict); } catch (ArgumentNullException) { dict = new SortedDictionary<TKey,TValue>(); }","preventionTips":["Initialize dictionaries at field declaration","Null-check dictionaries before exposing Keys","Avoid passing nullable dictionary references to view constructors"],"tags":["csharp","null-reference","argument"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}