EllanJiang/GameFramework · error · GameFrameworkException

Object type ' ' is invalid.

Error message

Object type '{0}' is invalid.

What it means

HasObjectPool(Type objectType) second check: the type must be assignable to ObjectBase (i.e. a pooled object type). Passing any other type (string, int, plain classes) is rejected with a formatted message including the offending type's full name, because only ObjectBase-derived types can be pooled.

Solutions

  1. Pass an ObjectBase-derived type (or typeof(T) where T : ObjectBase).
  2. Reinstate the 'where T : ObjectBase' generic constraint in helper code.
  3. Add a runtime guard: if (!typeof(ObjectBase).IsAssignableFrom(t)) skip/log before calling the manager.

Example fix

// before
bool has = poolManager.HasObjectPool(typeof(PlayerController));
// after
bool has = poolManager.HasObjectPool(typeof(PlayerItem)); // PlayerItem : ObjectBase
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof(ObjectBase).IsAssignableFrom(objectType))
{
    bool has = poolManager.HasObjectPool(objectType);
}

Type guard

bool IsPoolableType(Type t) => t != null && typeof(ObjectBase).IsAssignableFrom(t);

Try / catch

try { poolManager.HasObjectPool(objectType); }
catch (GameFrameworkException) { /* objectType is not ObjectBase-derived; log type name */ }

Prevention

When it happens

Trigger: Calling HasObjectPool(typeof(string)), HasObjectPool(typeof(int)), or any non-ObjectBase class; passing the pool wrapper type or a target type instead of the ObjectBase subclass.

Common situations: Confusing the pooled resource type with the ObjectBase-derived pool item type after refactors; generic code that lost its 'where T : ObjectBase' constraint; config data holding wrong type names.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/ObjectPool/ObjectPoolManager.cs:110

        {
            return InternalHasObjectPool(new TypeNamePair(typeof(T)));
        }

        /// <summary>
        /// 检查是否存在对象池。
        /// </summary>
        /// <param name="objectType">对象类型。</param>
        /// <returns>是否存在对象池。</returns>
        public bool HasObjectPool(Type objectType)
        {
            if (objectType == null)
            {
                throw new GameFrameworkException("Object type is invalid.");
            }

            if (!typeof(ObjectBase).IsAssignableFrom(objectType))
            {
                throw new GameFrameworkException(Utility.Text.Format("Object type '{0}' is invalid.", objectType.FullName));
            }

            return InternalHasObjectPool(new TypeNamePair(objectType));
        }

        /// <summary>
        /// 检查是否存在对象池。
        /// </summary>
        /// <typeparam name="T">对象类型。</typeparam>
        /// <param name="name">对象池名称。</param>
        /// <returns>是否存在对象池。</returns>
        public bool HasObjectPool<T>(string name) where T : ObjectBase
        {
            return InternalHasObjectPool(new TypeNamePair(typeof(T), name));
        }

        /// <summary>
        /// 检查是否存在对象池。

View on GitHub (pinned to d0c010b051)