{"record":{"id":"b1d6a7fb22c3a4c9","repo":"EllanJiang/GameFramework","slug":"object-type-is-invalid","errorCode":null,"errorMessage":"Object type is invalid.","messagePattern":"Object type is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/ObjectPool/ObjectPoolManager.cs","lineNumber":105,"sourceCode":"        /// 检查是否存在对象池。\n        /// </summary>\n        /// <typeparam name=\"T\">对象类型。</typeparam>\n        /// <returns>是否存在对象池。</returns>\n        public bool HasObjectPool<T>() where T : ObjectBase\n        {\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        {","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/ObjectPool/ObjectPoolManager.cs#L87-L123","documentation":"ObjectPoolManager.HasObjectPool(Type objectType) validates that the type is non-null and derives from ObjectBase. A null type cannot form the pool's TypeNamePair key, so the manager throws 'Object type is invalid.' as the first of two validation failures.","triggerScenarios":"Calling gameFrameworkObjectPoolComponent / ObjectPoolManager.HasObjectPool(null); a Type variable resolved via reflection (Type.GetType) that returned null because the type name string was wrong or assembly not loaded.","commonSituations":"Reflection lookups with misspelled assembly-qualified names; generic helpers where typeof(T) was replaced by a nullable Type field left unset; config-driven pool type strings not resolvable at runtime.","solutions":["Pass a concrete non-null type, e.g. typeof(MyItem) or item.GetType().","Fix the reflection call so Type.GetType succeeds (use assembly-qualified names) and check the result before use.","Use the generic HasObjectPool<T>() overload when the type is known at compile time."],"exampleFix":"// before\nType t = Type.GetType(\"MyItem\"); // returns null if not found\npoolManager.HasObjectPool(t);\n// after\npoolManager.HasObjectPool(typeof(MyItem));","handlingStrategy":"validation","validationCode":"if (objectType != null && 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 ex) { Debug.LogError($\"Invalid pool type query: {ex.Message}\"); }","preventionTips":["Prefer generic HasObjectPool<T>() when the type is compile-time known.","Check Type.GetType results for null before use; use assembly-qualified names.","Keep pool types listed in configs validated at load time."],"tags":["gameframework","objectpool","null-argument","reflection"],"backgroundTag":"null-argument","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"}