{"record":{"id":"781b77848bcb5ed7","repo":"EllanJiang/GameFramework","slug":"owner-type-is-invalid","errorCode":null,"errorMessage":"Owner type is invalid.","messagePattern":"Owner type is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Fsm/FsmManager.cs","lineNumber":115,"sourceCode":"        /// 检查是否存在有限状态机。\n        /// </summary>\n        /// <typeparam name=\"T\">有限状态机持有者类型。</typeparam>\n        /// <returns>是否存在有限状态机。</returns>\n        public bool HasFsm<T>() where T : class\n        {\n            return InternalHasFsm(new TypeNamePair(typeof(T)));\n        }\n\n        /// <summary>\n        /// 检查是否存在有限状态机。\n        /// </summary>\n        /// <param name=\"ownerType\">有限状态机持有者类型。</param>\n        /// <returns>是否存在有限状态机。</returns>\n        public bool HasFsm(Type ownerType)\n        {\n            if (ownerType == null)\n            {\n                throw new GameFrameworkException(\"Owner type is invalid.\");\n            }\n\n            return InternalHasFsm(new TypeNamePair(ownerType));\n        }\n\n        /// <summary>\n        /// 检查是否存在有限状态机。\n        /// </summary>\n        /// <typeparam name=\"T\">有限状态机持有者类型。</typeparam>\n        /// <param name=\"name\">有限状态机名称。</param>\n        /// <returns>是否存在有限状态机。</returns>\n        public bool HasFsm<T>(string name) where T : class\n        {\n            return InternalHasFsm(new TypeNamePair(typeof(T), name));\n        }\n\n        /// <summary>\n        /// 检查是否存在有限状态机。","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Fsm/FsmManager.cs#L97-L133","documentation":"FsmManager.HasFsm(Type ownerType) builds a TypeNamePair from the owner type to search its FSM registry. A null owner type would produce an invalid key, so GameFrameworkException('Owner type is invalid.') is thrown before the lookup.","triggerScenarios":"Calling gameFrameworkFsmManager.HasFsm(null); passing a type variable obtained via reflection that failed to resolve.","commonSituations":"Reflection-based code where Type.GetType returned null for a misspelled type name; generic helpers forwarding a null typeof result; config-driven systems storing type names as strings.","solutions":["Pass a concrete typeof(OwnerClass) to HasFsm","Fix reflection code so the Type is resolved (or fail earlier) before the lookup","Validate the type argument at the boundary of your helper methods","Replace string-based type resolution with compile-time generics where possible"],"exampleFix":"// before\nbool exists = fsmManager.HasFsm(ownerType); // ownerType may be null from reflection\n// after\nbool exists = ownerType != null && fsmManager.HasFsm(ownerType);","handlingStrategy":"type-guard","validationCode":"if (ownerType == null) throw new ArgumentNullException(nameof(ownerType));","typeGuard":"bool IsValidOwnerType(Type ownerType) => ownerType != null;","tryCatchPattern":"try { bool exists = fsmManager.HasFsm(ownerType); } catch (GameFrameworkException ex) when (ex.Message == \"Owner type is invalid.\") { /* treat as not-found or fix type resolution */ }","preventionTips":["Check Type.GetType results for null before use","Prefer typeof(T) over runtime Type resolution when possible","Fail fast at startup if reflection-based type lookups return null"],"tags":["fsm","null-argument","type-resolution"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}