{"record":{"id":"813597ced5c5b800","repo":"EllanJiang/GameFramework","slug":"object-type-0-is-invalid","errorCode":null,"errorMessage":"Object type '{0}' is invalid.","messagePattern":"Object type '(.+?)' is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/ObjectPool/ObjectPoolManager.cs","lineNumber":110,"sourceCode":"        {\n            return InternalHasObjectPool(new TypeNamePair(typeof(T)));\n        }\n\n        /// <summary>\n        /// 检查是否存在对象池。\n        /// </summary>\n        /// <param name=\"objectType\">对象类型。</param>\n        /// <returns>是否存在对象池。</returns>\n        public bool HasObjectPool(Type objectType)\n        {\n            if (objectType == null)\n            {\n                throw new GameFrameworkException(\"Object type is invalid.\");\n            }\n\n            if (!typeof(ObjectBase).IsAssignableFrom(objectType))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Object type '{0}' is invalid.\", objectType.FullName));\n            }\n\n            return InternalHasObjectPool(new TypeNamePair(objectType));\n        }\n\n        /// <summary>\n        /// 检查是否存在对象池。\n        /// </summary>\n        /// <typeparam name=\"T\">对象类型。</typeparam>\n        /// <param name=\"name\">对象池名称。</param>\n        /// <returns>是否存在对象池。</returns>\n        public bool HasObjectPool<T>(string name) where T : ObjectBase\n        {\n            return InternalHasObjectPool(new TypeNamePair(typeof(T), name));\n        }\n\n        /// <summary>\n        /// 检查是否存在对象池。","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/ObjectPool/ObjectPoolManager.cs#L92-L128","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass an ObjectBase-derived type (or typeof(T) where T : ObjectBase).","Reinstate the 'where T : ObjectBase' generic constraint in helper code.","Add a runtime guard: if (!typeof(ObjectBase).IsAssignableFrom(t)) skip/log before calling the manager."],"exampleFix":"// before\nbool has = poolManager.HasObjectPool(typeof(PlayerController));\n// after\nbool has = poolManager.HasObjectPool(typeof(PlayerItem)); // PlayerItem : ObjectBase","handlingStrategy":"type-guard","validationCode":"if (typeof(ObjectBase).IsAssignableFrom(objectType))\n{\n    bool has = poolManager.HasObjectPool(objectType);\n}","typeGuard":"bool IsPoolableType(Type t) => t != null && typeof(ObjectBase).IsAssignableFrom(t);","tryCatchPattern":"try { poolManager.HasObjectPool(objectType); }\ncatch (GameFrameworkException) { /* objectType is not ObjectBase-derived; log type name */ }","preventionTips":["Keep 'where T : ObjectBase' constraints on generic pooling helpers.","Always pass the ObjectBase-derived item type, not the raw resource type.","Document pool item classes clearly so callers use the right type."],"tags":["gameframework","objectpool","type-mismatch","csharp"],"backgroundTag":"type-mismatch","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}