EllanJiang/GameFramework · error · GameFrameworkException

Can not find Game Framework module type

Error message

Can not find Game Framework module type '{0}'.

What it means

GetModule<T>() builds the concrete module type name from the interface by convention ('Namespace.InterfaceNameWithoutI') and calls Type.GetType on it. When no such concrete class exists (or it is not loaded in the current assembly context), Type.GetType returns null and this error is thrown.

Solutions

  1. Create a concrete class named InterfaceName minus the leading 'I' in the same namespace as the interface, derived from GameFrameworkModule
  2. Ensure the concrete class is in an assembly referenced/loaded at runtime (avoid IL2CPP code stripping of module types)
  3. Verify the interface is named with the 'I' prefix (e.g. IFoo -> Foo); a non-I interface name produces a wrong type name

Example fix

// before
public interface GameFramework.MyModule.IMyModule { } // no concrete class
// after
namespace GameFramework.MyModule
{
    public interface IMyModule : GameFramework.IGameFrameworkModule { }
    internal sealed class MyModule : GameFrameworkModule, IMyModule { /* ... */ }
}
Defensive patterns

Strategy: validation

Validate before calling

string moduleName = typeof(T).Namespace + "." + typeof(T).Name.Substring(1);
if (Type.GetType(moduleName) != null)
{
    var module = GameFrameworkEntry.GetModule<T>();
}

Type guard

static bool HasConcreteModuleType<T>()
{
    var t = typeof(T);
    return t.IsInterface && t.Name.StartsWith("I") && Type.GetType($"{t.Namespace}.{t.Name.Substring(1)}") != null;
}

Try / catch

try { var m = GameFrameworkEntry.GetModule<T>(); }
catch (GameFrameworkException ex) { Debug.LogError($"Concrete type for {typeof(T)} not found: {ex.Message}"); }

Prevention

When it happens

Trigger: Calling GameFrameworkEntry.GetModule<T>() where the matching concrete class (e.g. IMyModule -> MyModule) does not exist in the same namespace, has been renamed, lives in an assembly not loaded/resolvable by Type.GetType, or the interface name does not follow the I-prefix convention.

Common situations: Implementing a custom module interface but forgetting the concrete class; renaming the concrete class or namespace; Unity IL2CPP/assembly stripping removing the concrete type so Type.GetType fails; interface not following the 'I' prefix convention so the Substring(1) mangles the name.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/86e5f466ccbc8374. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Base/GameFrameworkEntry.cs:72

        /// <remarks>如果要获取的游戏框架模块不存在,则自动创建该游戏框架模块。</remarks>
        public static T GetModule<T>() where T : class
        {
            Type interfaceType = typeof(T);
            if (!interfaceType.IsInterface)
            {
                throw new GameFrameworkException(Utility.Text.Format("You must get module by interface, but '{0}' is not.", interfaceType.FullName));
            }

            if (!interfaceType.FullName.StartsWith("GameFramework.", StringComparison.Ordinal))
            {
                throw new GameFrameworkException(Utility.Text.Format("You must get a Game Framework module, but '{0}' is not.", interfaceType.FullName));
            }

            string moduleName = Utility.Text.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name.Substring(1));
            Type moduleType = Type.GetType(moduleName);
            if (moduleType == null)
            {
                throw new GameFrameworkException(Utility.Text.Format("Can not find Game Framework module type '{0}'.", moduleName));
            }

            return GetModule(moduleType) as T;
        }

        /// <summary>
        /// 获取游戏框架模块。
        /// </summary>
        /// <param name="moduleType">要获取的游戏框架模块类型。</param>
        /// <returns>要获取的游戏框架模块。</returns>
        /// <remarks>如果要获取的游戏框架模块不存在,则自动创建该游戏框架模块。</remarks>
        private static GameFrameworkModule GetModule(Type moduleType)
        {
            foreach (GameFrameworkModule module in s_GameFrameworkModules)
            {
                if (module.GetType() == moduleType)
                {
                    return module;

View on GitHub (pinned to d0c010b051)