EllanJiang/GameFramework · error · GameFrameworkException
Owner type is invalid.
Error message
Owner type is invalid.
What it means
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.
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
Example fix
// before bool exists = fsmManager.HasFsm(ownerType); // ownerType may be null from reflection // after bool exists = ownerType != null && fsmManager.HasFsm(ownerType);
Defensive patterns
Strategy: type-guard
Validate before calling
if (ownerType == null) throw new ArgumentNullException(nameof(ownerType));
Type guard
bool IsValidOwnerType(Type ownerType) => ownerType != null;
Try / catch
try { bool exists = fsmManager.HasFsm(ownerType); } catch (GameFrameworkException ex) when (ex.Message == "Owner type is invalid.") { /* treat as not-found or fix type resolution */ } Prevention
- 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
When it happens
Trigger: Calling gameFrameworkFsmManager.HasFsm(null); passing a type variable obtained via reflection that failed to resolve.
Common situations: 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.
Related errors
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/781b77848bcb5ed7.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Fsm/FsmManager.cs:115
/// 检查是否存在有限状态机。
/// </summary>
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
/// <returns>是否存在有限状态机。</returns>
public bool HasFsm<T>() where T : class
{
return InternalHasFsm(new TypeNamePair(typeof(T)));
}
/// <summary>
/// 检查是否存在有限状态机。
/// </summary>
/// <param name="ownerType">有限状态机持有者类型。</param>
/// <returns>是否存在有限状态机。</returns>
public bool HasFsm(Type ownerType)
{
if (ownerType == null)
{
throw new GameFrameworkException("Owner type is invalid.");
}
return InternalHasFsm(new TypeNamePair(ownerType));
}
/// <summary>
/// 检查是否存在有限状态机。
/// </summary>
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
/// <param name="name">有限状态机名称。</param>
/// <returns>是否存在有限状态机。</returns>
public bool HasFsm<T>(string name) where T : class
{
return InternalHasFsm(new TypeNamePair(typeof(T), name));
}
/// <summary>
/// 检查是否存在有限状态机。View on GitHub (pinned to d0c010b051)