EllanJiang/GameFramework · error · GameFrameworkException

ReferenceType is invalid.

Error message

ReferenceType is invalid.

What it means

GetReferenceCollection resolves (and lazily creates) the ReferenceCollection for a given reference type. Although callers upstream already validated the type, this private helper re-checks for null as an internal invariant; a null here means the validation chain was bypassed or broken. It is reached from Acquire, Release, Add, Remove, and RemoveAll.

Solutions

  1. Ensure every path that resolves a collection calls InternalCheckReferenceType (or passes a non-null type) first.
  2. In a forked/modified ReferencePool, restore the validation call before GetReferenceCollection.
  3. If this fires in stock GameFramework, treat it as a bug and inspect the modified source of ReferencePool.cs.

Example fix

// before (custom overload)
private static void Remove(Type referenceType)
{
    GetReferenceCollection(referenceType).Remove(); // null type slips through
}

// after
private static void Remove(Type referenceType)
{
    InternalCheckReferenceType(referenceType);
    GetReferenceCollection(referenceType).Remove();
}
Defensive patterns

Strategy: try-catch

Validate before calling

// only relevant when patching the framework:
InternalCheckReferenceType(referenceType); // must precede GetReferenceCollection

Type guard

bool Resolvable(Type t) => t != null && typeof(IReference).IsAssignableFrom(t) && t.IsClass && !t.IsAbstract;

Try / catch

try { ReferencePool.Acquire<T>(); }
catch (GameFrameworkException ex) when (ex.Message == "ReferenceType is invalid.")
{
    // invariant broken — audit custom code paths into ReferencePool internals
}

Prevention

When it happens

Trigger: An internal-invariant failure: InternalCheckReferenceType would normally reject a null type before GetReferenceCollection runs, so hitting this throw implies a new code path called GetReferenceCollection directly or the validation logic changed — essentially unreachable through the public API unless the framework is modified.

Common situations: Custom forks or patched builds of ReferencePool that skip InternalCheckReferenceType; new overloads added by the team calling GetReferenceCollection without prior validation.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/Base/ReferencePool/ReferencePool.cs:209

                throw new GameFrameworkException("Reference type is invalid.");
            }

            if (!referenceType.IsClass || referenceType.IsAbstract)
            {
                throw new GameFrameworkException("Reference type is not a non-abstract class type.");
            }

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

        private static ReferenceCollection GetReferenceCollection(Type referenceType)
        {
            if (referenceType == null)
            {
                throw new GameFrameworkException("ReferenceType is invalid.");
            }

            ReferenceCollection referenceCollection = null;
            lock (s_ReferenceCollections)
            {
                if (!s_ReferenceCollections.TryGetValue(referenceType, out referenceCollection))
                {
                    referenceCollection = new ReferenceCollection(referenceType);
                    s_ReferenceCollections.Add(referenceType, referenceCollection);
                }
            }

            return referenceCollection;
        }
    }
}

View on GitHub (pinned to d0c010b051)