{"record":{"id":"2bd111515392e83c","repo":"EllanJiang/GameFramework","slug":"resource-manager-is-invalid-dataprovidercreator","errorCode":null,"errorMessage":"Resource manager is invalid.","messagePattern":"Resource manager is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Base/DataProvider/DataProviderCreator.cs","lineNumber":63,"sourceCode":"\n        /// <summary>\n        /// 创建数据提供者。\n        /// </summary>\n        /// <typeparam name=\"T\">数据提供者的持有者的类型。</typeparam>\n        /// <param name=\"owner\">数据提供者的持有者。</param>\n        /// <param name=\"resourceManager\">资源管理器。</param>\n        /// <param name=\"dataProviderHelper\">数据提供者辅助器。</param>\n        /// <returns>创建的数据提供者。</returns>\n        public static IDataProvider<T> Create<T>(T owner, IResourceManager resourceManager, IDataProviderHelper<T> dataProviderHelper)\n        {\n            if (owner == null)\n            {\n                throw new GameFrameworkException(\"Owner is invalid.\");\n            }\n\n            if (resourceManager == null)\n            {\n                throw new GameFrameworkException(\"Resource manager is invalid.\");\n            }\n\n            if (dataProviderHelper == null)\n            {\n                throw new GameFrameworkException(\"Data provider helper is invalid.\");\n            }\n\n            DataProvider<T> dataProvider = new DataProvider<T>(owner);\n            dataProvider.SetResourceManager(resourceManager);\n            dataProvider.SetDataProviderHelper(dataProviderHelper);\n            return dataProvider;\n        }\n    }\n}\n","sourceCodeStart":45,"sourceCodeEnd":78,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Base/DataProvider/DataProviderCreator.cs#L45-L78","documentation":"DataProviderCreator.Create<T>() throws GameFrameworkException('Resource manager is invalid.') when the resourceManager argument is null. The data provider needs an IResourceManager to load its data, so the factory refuses to construct one without it. This is fail-fast validation performed after the owner check.","triggerScenarios":"Calling DataProviderCreator.Create<T>(owner, null, dataProviderHelper). Usually caused by the IResourceManager not having been built yet, a failed dependency-injection resolution, or passing the wrong variable (null) where the resource manager was intended.","commonSituations":"Calling Create before GameFramework's resource component/module is initialized; DI container failed to register or resolve IResourceManager; copying example code without obtaining the framework's resource manager instance first.","solutions":["Obtain the initialized IResourceManager (e.g. from the GameFramework entry/component) and pass it to Create<T>","Ensure framework resource modules are initialized before creating data providers","If using DI, verify IResourceManager is registered and the resolved instance is not null before calling Create"],"exampleFix":"// before\nvar provider = DataProviderCreator.Create<Player>(player, null, helper);\n// after\nIResourceManager resourceManager = GameFrameworkEntry.GetModule<ResourceManager>();\nif (resourceManager == null) { throw new InvalidOperationException(\"ResourceManager not initialized\"); }\nvar provider = DataProviderCreator.Create<Player>(player, resourceManager, helper);","handlingStrategy":"validation","validationCode":"if (resourceManager == null) throw new ArgumentNullException(nameof(resourceManager));\nDataProviderCreator.Create<T>(owner, resourceManager, helper);","typeGuard":"bool HasResourceManager(IResourceManager rm) => rm != null;","tryCatchPattern":"try\n{\n    var provider = DataProviderCreator.Create<T>(owner, resourceManager, helper);\n}\ncatch (GameFrameworkException ex) when (ex.Message == \"Resource manager is invalid.\")\n{\n    // initialize framework resource module before creating providers\n}","preventionTips":["Initialize GameFramework resource modules before any data provider is created","Resolve IResourceManager once at startup and reuse the instance","Never pass literal null for the resource manager; inject it explicitly"],"tags":["csharp","null-argument","gameframework","resource-manager"],"backgroundTag":"null-argument","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"}