EllanJiang/GameFramework · error · GameFrameworkException
Key is invalid.
Error message
Key is invalid.
What it means
HasRawString validates its dictionary key before checking the localization dictionary. An empty or null key can never exist in m_Dictionary, so rather than returning a misleading false the manager throws to signal a caller bug. Raw strings are the unformatted entries stored under a key in the localization system.
Solutions
- Ensure the key is a non-empty string before calling, e.g. guard with if (!string.IsNullOrEmpty(key)).
- Fix the data source so localization table rows always carry a key.
- If a missing key is expected, treat it as 'not found' in your own wrapper instead of passing null/empty into the API.
Example fix
// before bool exists = Localization.HasRawString(configKey); // configKey may be "" // after bool exists = !string.IsNullOrEmpty(configKey) && Localization.HasRawString(configKey);
Defensive patterns
Strategy: validation
Validate before calling
bool exists = !string.IsNullOrEmpty(key) && Localization.HasRawString(key);
Try / catch
try { exists = Localization.HasRawString(key); }
catch (GameFrameworkException) { exists = false; } Prevention
- Guard all raw-string lookups with string.IsNullOrEmpty checks.
- Ensure localization data sources never emit blank key cells.
- Wrap localization access in a helper layer that normalizes/validates keys once.
When it happens
Trigger: Calling HasRawString(null) or HasRawString(""), usually when the key string came from an unset variable, an empty UI field, or a parsed data row with a missing key column.
Common situations: Localization table rows whose key cell is blank; string variables not yet initialized at call time; concatenating key parts where one segment is empty producing an empty or clearly malformed key.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Localization helper is invalid.
- Type name is invalid.
- Data string is invalid.
- Data bytes is invalid.
- Path is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/9aa2cc80bc182c63.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Localization/LocalizationManager.cs:993
return Utility.Text.Format(value, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16);
}
catch (Exception exception)
{
string args = Utility.Text.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15}", arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16);
return Utility.Text.Format("<Error>{0},{1},{2},{3}", key, value, args, exception);
}
}
/// <summary>
/// 是否存在字典。
/// </summary>
/// <param name="key">字典主键。</param>
/// <returns>是否存在字典。</returns>
public bool HasRawString(string key)
{
if (string.IsNullOrEmpty(key))
{
throw new GameFrameworkException("Key is invalid.");
}
return m_Dictionary.ContainsKey(key);
}
/// <summary>
/// 根据字典主键获取字典值。
/// </summary>
/// <param name="key">字典主键。</param>
/// <returns>字典值。</returns>
public string GetRawString(string key)
{
if (string.IsNullOrEmpty(key))
{
throw new GameFrameworkException("Key is invalid.");
}
string value = null;View on GitHub (pinned to d0c010b051)