EllanJiang/GameFramework · error · GameFrameworkException
Dictionary is invalid.
Error message
Dictionary is invalid.
What it means
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.
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.
Example fix
// before
foreach (var pair in multiDictionary) { ... } // internal dictionary null
// after
if (multiDictionary != null)
{
foreach (var pair in multiDictionary) { ... }
} Defensive patterns
Strategy: type-guard
Validate before calling
if (multiDictionary == null) { return; } Type guard
static bool CanEnumerate<TKey, TValue>(GameFrameworkMultiDictionary<TKey, TValue> dict) => dict != null;
Try / catch
try { foreach (var pair in multiDictionary) { ... } } catch (GameFrameworkException) { /* treat as empty */ } Prevention
- Initialize internal Dictionary in the wrapper constructor
- Null-check before foreach
- Do not rely on Unity deserialization to populate the dictionary
When it happens
Trigger: 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.
Common situations: 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).
Related errors
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/1b1e5ba867811464.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Base/GameFrameworkMultiDictionary.cs:229
/// <returns>循环访问集合的枚举数。</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
/// <summary>
/// 循环访问集合的枚举数。
/// </summary>
[StructLayout(LayoutKind.Auto)]
public struct Enumerator : IEnumerator<KeyValuePair<TKey, GameFrameworkLinkedListRange<TValue>>>, IEnumerator
{
private Dictionary<TKey, GameFrameworkLinkedListRange<TValue>>.Enumerator m_Enumerator;
internal Enumerator(Dictionary<TKey, GameFrameworkLinkedListRange<TValue>> dictionary)
{
if (dictionary == null)
{
throw new GameFrameworkException("Dictionary is invalid.");
}
m_Enumerator = dictionary.GetEnumerator();
}
/// <summary>
/// 获取当前结点。
/// </summary>
public KeyValuePair<TKey, GameFrameworkLinkedListRange<TValue>> Current
{
get
{
return m_Enumerator.Current;
}
}
/// <summary>
/// 获取当前的枚举数。View on GitHub (pinned to d0c010b051)