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

  1. Ensure the key is a non-empty string before calling, e.g. guard with if (!string.IsNullOrEmpty(key)).
  2. Fix the data source so localization table rows always carry a key.
  3. 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

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


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)