{"record":{"id":"1b1e5ba867811464","repo":"EllanJiang/GameFramework","slug":"dictionary-is-invalid","errorCode":null,"errorMessage":"Dictionary is invalid.","messagePattern":"Dictionary is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Base/GameFrameworkMultiDictionary.cs","lineNumber":229,"sourceCode":"        /// <returns>循环访问集合的枚举数。</returns>\n        IEnumerator IEnumerable.GetEnumerator()\n        {\n            return GetEnumerator();\n        }\n\n        /// <summary>\n        /// 循环访问集合的枚举数。\n        /// </summary>\n        [StructLayout(LayoutKind.Auto)]\n        public struct Enumerator : IEnumerator<KeyValuePair<TKey, GameFrameworkLinkedListRange<TValue>>>, IEnumerator\n        {\n            private Dictionary<TKey, GameFrameworkLinkedListRange<TValue>>.Enumerator m_Enumerator;\n\n            internal Enumerator(Dictionary<TKey, GameFrameworkLinkedListRange<TValue>> dictionary)\n            {\n                if (dictionary == null)\n                {\n                    throw new GameFrameworkException(\"Dictionary is invalid.\");\n                }\n\n                m_Enumerator = dictionary.GetEnumerator();\n            }\n\n            /// <summary>\n            /// 获取当前结点。\n            /// </summary>\n            public KeyValuePair<TKey, GameFrameworkLinkedListRange<TValue>> Current\n            {\n                get\n                {\n                    return m_Enumerator.Current;\n                }\n            }\n\n            /// <summary>\n            /// 获取当前的枚举数。","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Base/GameFrameworkMultiDictionary.cs#L211-L247","documentation":"GameFrameworkMultiDictionary<TKey, TValue> creates a nested Enumerator from the caller-supplied Dictionary<TKey, GameFrameworkLinkedListRange<TValue>>. The library throws when the dictionary argument is null, since there is nothing to enumerate. This is a fail-fast guard at the start of enumeration.","triggerScenarios":"Constructing GameFrameworkMultiDictionary<TKey,TValue>.Enumerator with a null dictionary, i.e. `new GameFrameworkMultiDictionary<TKey,TValue>.Enumerator(null)`, typically via GetEnumerator() on a wrapper whose internal dictionary is null.","commonSituations":"foreach over a GameFrameworkMultiDictionary wrapper that was default-constructed or deserialized without its internal dictionary being initialized (common with Unity serialization of non-serialized fields).","solutions":["Ensure the GameFrameworkMultiDictionary wrapper initializes its internal Dictionary before enumeration.","Null-check the multi-dictionary before foreach or GetEnumerator().","Initialize the dictionary field in the constructor/Awake instead of relying on deserialization.","Wrap enumeration in try-catch for GameFrameworkException when state is uncertain."],"exampleFix":"// before\nforeach (var pair in multiDictionary) { ... } // internal dictionary null\n// after\nif (multiDictionary != null)\n{\n    foreach (var pair in multiDictionary) { ... }\n}","handlingStrategy":"type-guard","validationCode":"if (multiDictionary == null) { return; }","typeGuard":"static bool CanEnumerate<TKey, TValue>(GameFrameworkMultiDictionary<TKey, TValue> dict) => dict != null;","tryCatchPattern":"try { foreach (var pair in multiDictionary) { ... } } catch (GameFrameworkException) { /* treat as empty */ }","preventionTips":["Initialize internal Dictionary in the wrapper constructor","Null-check before foreach","Do not rely on Unity deserialization to populate the dictionary"],"tags":["csharp","null-argument","enumerator","dictionary"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}