{"record":{"id":"346f8874e79b4c63","repo":"EllanJiang/GameFramework","slug":"reference-type-0-is-invalid","errorCode":null,"errorMessage":"Reference type '{0}' is invalid.","messagePattern":"Reference type '(.+?)' is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Base/ReferencePool/ReferencePool.cs","lineNumber":201,"sourceCode":"        {\n            if (!m_EnableStrictCheck)\n            {\n                return;\n            }\n\n            if (referenceType == null)\n            {\n                throw new GameFrameworkException(\"Reference type is invalid.\");\n            }\n\n            if (!referenceType.IsClass || referenceType.IsAbstract)\n            {\n                throw new GameFrameworkException(\"Reference type is not a non-abstract class type.\");\n            }\n\n            if (!typeof(IReference).IsAssignableFrom(referenceType))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Reference type '{0}' is invalid.\", referenceType.FullName));\n            }\n        }\n\n        private static ReferenceCollection GetReferenceCollection(Type referenceType)\n        {\n            if (referenceType == null)\n            {\n                throw new GameFrameworkException(\"ReferenceType is invalid.\");\n            }\n\n            ReferenceCollection referenceCollection = null;\n            lock (s_ReferenceCollections)\n            {\n                if (!s_ReferenceCollections.TryGetValue(referenceType, out referenceCollection))\n                {\n                    referenceCollection = new ReferenceCollection(referenceType);\n                    s_ReferenceCollections.Add(referenceType, referenceCollection);\n                }","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Base/ReferencePool/ReferencePool.cs#L183-L219","documentation":"After confirming the type is a non-abstract class, InternalCheckReferenceType verifies the type actually implements IReference. A type that is a valid class but does not implement the pooling interface cannot be tracked or cleared by the pool, so it is rejected with a message naming the offending type's full name.","triggerScenarios":"Calling ReferencePool.Acquire<T>/Add<T>/Release/Remove with a plain class (one that implements neither IReference nor a derived interface) — often a POCO, a struct-wrapped class, or a class implementing a similarly named custom interface.","commonSituations":"Refactoring that moved IReference to a different namespace and left the class implementing an old/shim interface; pooling a third-party or data class that was never meant for ReferencePool; using two different IReference interfaces from different framework versions in the same project.","solutions":["Make the pooled class implement the framework's IReference interface (implementing Clear() as required).","Confirm there is only one IReference type in scope — remove stale/duplicate interface definitions from other framework copies.","If the class cannot implement IReference, use a different pooling mechanism instead of ReferencePool."],"exampleFix":"// before\npublic class DamageInfo { public int Amount; } // no IReference\n\n// after\npublic class DamageInfo : IReference\n{\n    public int Amount;\n    public void Clear() { Amount = 0; }\n}","handlingStrategy":"type-guard","validationCode":"System.Diagnostics.Debug.Assert(\n    typeof(IReference).IsAssignableFrom(typeof(T)),\n    typeof(T).FullName + \" must implement IReference before pooling.\");","typeGuard":"static bool ImplementsIReference(Type t) => typeof(IReference).IsAssignableFrom(t) && t.IsClass && !t.IsAbstract;","tryCatchPattern":"try { ReferencePool.Acquire<T>(); }\ncatch (GameFrameworkException ex) when (ex.Message.Contains(\"is invalid\") && ex.Message.Contains(typeof(T).Name))\n{\n    // T does not implement IReference — add the interface or use another pool\n}","preventionTips":["Make every pooled class implement IReference and its Clear() method from day one.","Remove duplicate IReference definitions when consolidating framework copies to avoid 'implements the wrong IReference' bugs.","Add a reflection-based startup check that all types marked [Poolable] implement IReference."],"tags":["object-pool","type-validation","interface","reference-pool"],"backgroundTag":"type-mismatch","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}