{"record":{"id":"1c7a1049c28d8e1b","repo":"EllanJiang/GameFramework","slug":"can-not-create-module-0","errorCode":null,"errorMessage":"Can not create module '{0}'.","messagePattern":"Can not create module '(.+?)'\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Base/GameFrameworkEntry.cs","lineNumber":107,"sourceCode":"                {\n                    return module;\n                }\n            }\n\n            return CreateModule(moduleType);\n        }\n\n        /// <summary>\n        /// 创建游戏框架模块。\n        /// </summary>\n        /// <param name=\"moduleType\">要创建的游戏框架模块类型。</param>\n        /// <returns>要创建的游戏框架模块。</returns>\n        private static GameFrameworkModule CreateModule(Type moduleType)\n        {\n            GameFrameworkModule module = (GameFrameworkModule)Activator.CreateInstance(moduleType);\n            if (module == null)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Can not create module '{0}'.\", moduleType.FullName));\n            }\n\n            LinkedListNode<GameFrameworkModule> current = s_GameFrameworkModules.First;\n            while (current != null)\n            {\n                if (module.Priority > current.Value.Priority)\n                {\n                    break;\n                }\n\n                current = current.Next;\n            }\n\n            if (current != null)\n            {\n                s_GameFrameworkModules.AddBefore(current, module);\n            }\n            else","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Base/GameFrameworkEntry.cs#L89-L125","documentation":"CreateModule instantiates the resolved module type via Activator.CreateInstance and casts it to GameFrameworkModule. If instantiation produces null (or fails to yield a GameFrameworkModule), the framework throws this error because it cannot create the requested module instance.","triggerScenarios":"Activator.CreateInstance(moduleType) returns null or a non-GameFrameworkModule object — e.g. the 'module type' resolved by naming convention is actually not a concrete GameFrameworkModule subclass, or an exotic type whose Activator.CreateInstance yields null.","commonSituations":"Custom module classes that do not inherit GameFrameworkModule; types with no accessible parameterless constructor in restricted environments; assembly issues causing the cast/creation to fail unexpectedly.","solutions":["Make the module class inherit from GameFrameworkModule and give it a public parameterless constructor","Confirm the type passed to GetModule(Type) is the concrete module class, not an interface or unrelated class","Step through with a debugger to inspect the exception thrown internally by Activator.CreateInstance (often wrapped/hidden)"],"exampleFix":"// before\ninternal sealed class MyModule : IMyModule { } // not a GameFrameworkModule\n// after\ninternal sealed class MyModule : GameFrameworkModule, IMyModule\n{\n    public MyModule() { }\n    protected internal override void Update(float elapseSeconds, float realElapseSeconds) { }\n}","handlingStrategy":"try-catch","validationCode":"var moduleType = Type.GetType(expectedModuleName);\nif (moduleType != null && typeof(GameFrameworkModule).IsAssignableFrom(moduleType) && moduleType.GetConstructor(Type.EmptyTypes) != null)\n{\n    var module = GameFrameworkEntry.GetModule(moduleType);\n}","typeGuard":"static bool IsInstantiableGameFrameworkModule(Type t) => !t.IsAbstract && !t.IsInterface && typeof(GameFrameworkModule).IsAssignableFrom(t) && t.GetConstructor(Type.EmptyTypes) != null;","tryCatchPattern":"try { var m = GameFrameworkEntry.GetModule<T>(); }\ncatch (GameFrameworkException ex) { Debug.LogError($\"Failed to create module {typeof(T)}: {ex.Message}\"); }","preventionTips":["Derive every module class from GameFrameworkModule with a public parameterless constructor","Never pass interfaces or abstract types as the module type","Test module creation in an editor bootstrap before builds"],"tags":["gameframework","module-init","reflection"],"backgroundTag":"module-init-failed","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}