{"record":{"id":"1d7bf623695a0942","repo":"EllanJiang/GameFramework","slug":"you-must-get-a-game-framework-module-but-0-is-not","errorCode":null,"errorMessage":"You must get a Game Framework module, but '{0}' is not.","messagePattern":"You must get a Game Framework module, but '(.+?)' is not\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Base/GameFrameworkEntry.cs","lineNumber":65,"sourceCode":"        }\n\n        /// <summary>\n        /// 获取游戏框架模块。\n        /// </summary>\n        /// <typeparam name=\"T\">要获取的游戏框架模块类型。</typeparam>\n        /// <returns>要获取的游戏框架模块。</returns>\n        /// <remarks>如果要获取的游戏框架模块不存在，则自动创建该游戏框架模块。</remarks>\n        public static T GetModule<T>() where T : class\n        {\n            Type interfaceType = typeof(T);\n            if (!interfaceType.IsInterface)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"You must get module by interface, but '{0}' is not.\", interfaceType.FullName));\n            }\n\n            if (!interfaceType.FullName.StartsWith(\"GameFramework.\", StringComparison.Ordinal))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"You must get a Game Framework module, but '{0}' is not.\", interfaceType.FullName));\n            }\n\n            string moduleName = Utility.Text.Format(\"{0}.{1}\", interfaceType.Namespace, interfaceType.Name.Substring(1));\n            Type moduleType = Type.GetType(moduleName);\n            if (moduleType == null)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Can not find Game Framework module type '{0}'.\", moduleName));\n            }\n\n            return GetModule(moduleType) as T;\n        }\n\n        /// <summary>\n        /// 获取游戏框架模块。\n        /// </summary>\n        /// <param name=\"moduleType\">要获取的游戏框架模块类型。</param>\n        /// <returns>要获取的游戏框架模块。</returns>\n        /// <remarks>如果要获取的游戏框架模块不存在，则自动创建该游戏框架模块。</remarks>","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Base/GameFrameworkEntry.cs#L47-L83","documentation":"GameFrameworkEntry.GetModule<T>() resolves the concrete module class from a module interface by naming convention: the concrete type must live in the same namespace with the leading 'I' stripped from the interface name, and the interface's full name must start with 'GameFramework.'. This error is thrown when the passed interface type is not a Game Framework type, i.e. its FullName does not begin with the 'GameFramework.' prefix, so module resolution cannot proceed.","triggerScenarios":"Calling GameFrameworkEntry.GetModule<T>() where T is an interface whose full type name does not start with 'GameFramework.' — e.g. a custom module interface declared under a user namespace like 'MyGame.IMyModule', or accidentally passing a non-module interface.","commonSituations":"Developers creating their own custom module interfaces outside the GameFramework namespace; typos or renamed namespaces after moving code; passing an unrelated interface by mistake to GetModule.","solutions":["Declare the module interface in a namespace starting with 'GameFramework.' (e.g. 'GameFramework.MyModule.IMyModule') or use a built-in interface such as GameFramework.IObjectPoolManager","Verify with typeof(T).FullName.StartsWith(\"GameFramework.\") before calling GetModule","If you intended a custom module, register/obtain it through your own module system instead of GameFrameworkEntry"],"exampleFix":"// before\nvar module = GameFrameworkEntry.GetModule<IMyModule>(); // MyGame namespace\n// after\nnamespace GameFramework.MyModule { public interface IMyModule : GameFramework.IGameFrameworkModule { } }\nvar module = GameFrameworkEntry.GetModule<GameFramework.MyModule.IMyModule>();","handlingStrategy":"validation","validationCode":"if (typeof(T).IsInterface && typeof(T).FullName.StartsWith(\"GameFramework.\", StringComparison.Ordinal))\n{\n    var module = GameFrameworkEntry.GetModule<T>();\n}","typeGuard":"static bool IsGameFrameworkModuleInterface<T>() => typeof(T).IsInterface && typeof(T).FullName != null && typeof(T).FullName.StartsWith(\"GameFramework.\", StringComparison.Ordinal);","tryCatchPattern":"try { var m = GameFrameworkEntry.GetModule<T>(); }\ncatch (GameFrameworkException ex) { Debug.LogError($\"{typeof(T).FullName} is not a GameFramework module interface: {ex.Message}\"); }","preventionTips":["Only pass interfaces from the GameFramework namespace to GetModule","Keep custom module interfaces under a 'GameFramework.' namespace","Add a unit test asserting every module interface used starts with 'GameFramework.'"],"tags":["gameframework","module-lookup","naming-convention"],"backgroundTag":"invalid-argument-value","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"}