EllanJiang/GameFramework · error · GameFrameworkException

Object type is invalid.

Error message

Object type is invalid.

What it means

The non-generic GetObject(Type objectType, string settingName) throws this when the objectType argument is null. The manager needs the target Type to deserialize the stored value and cannot proceed without it. Argument-validation guard.

Solutions

  1. Pass a valid runtime Type (e.g., typeof(AudioConfig)).
  2. If resolving by name, use Type.GetType with assembly-qualified name and assert the result is non-null.
  3. Prefer the generic overload GetObject<T>(settingName) to avoid passing Type explicitly.
  4. Log the type name string when reflection resolution returns null to find the config typo.

Example fix

// before
Type t = Type.GetType("GameConfig"); // null, missing assembly qualification
var cfg = m_Setting.GetObject(t, "GameConfig");
// after
Type t = typeof(GameConfig); // or Type.GetType("MyGame.GameConfig, Assembly-CSharp")
var cfg = m_Setting.GetObject(t, "GameConfig");
Defensive patterns

Strategy: type-guard

Validate before calling

if (objectType != null && !string.IsNullOrEmpty(settingName))
{
    var obj = settingManager.GetObject(objectType, settingName);
}

Type guard

bool IsValidTypeArg(Type t) => t != null; // combine with key check

Try / catch

try { var obj = mgr.GetObject(type, key); }
catch (GameFrameworkException ex) when (ex.Message == "Object type is invalid.") { Log.Error($"Type failed to resolve"); return null; }

Prevention

When it happens

Trigger: Calling SettingManager.GetObject(null, settingName), e.g., a Type variable obtained via reflection (Type.GetType) that failed to resolve, or a null generic parameter passed through a wrapper.

Common situations: Reflection-based loading where Type.GetType("Namespace.Type") returns null due to missing assembly qualification; plugin/type moved to another assembly after a version upgrade; dynamic type lookup built from config strings.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/3c5f812bb32d0f06. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Setting/SettingManager.cs:464

            return m_SettingHelper.GetObject<T>(settingName);
        }

        /// <summary>
        /// 从指定游戏配置项中读取对象。
        /// </summary>
        /// <param name="objectType">要读取对象的类型。</param>
        /// <param name="settingName">要获取游戏配置项的名称。</param>
        /// <returns>读取的对象。</returns>
        public object GetObject(Type objectType, string settingName)
        {
            if (m_SettingHelper == null)
            {
                throw new GameFrameworkException("Setting helper is invalid.");
            }

            if (objectType == null)
            {
                throw new GameFrameworkException("Object type is invalid.");
            }

            if (string.IsNullOrEmpty(settingName))
            {
                throw new GameFrameworkException("Setting name is invalid.");
            }

            return m_SettingHelper.GetObject(objectType, settingName);
        }

        /// <summary>
        /// 从指定游戏配置项中读取对象。
        /// </summary>
        /// <typeparam name="T">要读取对象的类型。</typeparam>
        /// <param name="settingName">要获取游戏配置项的名称。</param>
        /// <param name="defaultObj">当指定的游戏配置项不存在时,返回此默认对象。</param>
        /// <returns>读取的对象。</returns>
        public T GetObject<T>(string settingName, T defaultObj)

View on GitHub (pinned to d0c010b051)