{"record":{"id":"1a041811f732a222","repo":"EllanJiang/GameFramework","slug":"data-provider-helper-is-invalid-dataprovidercreator","errorCode":null,"errorMessage":"Data provider helper is invalid.","messagePattern":"Data provider helper is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Base/DataProvider/DataProviderCreator.cs","lineNumber":68,"sourceCode":"        /// <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":50,"sourceCodeEnd":78,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Base/DataProvider/DataProviderCreator.cs#L50-L78","documentation":"DataProviderCreator.Create<T>() throws GameFrameworkException('Data provider helper is invalid.') when the dataProviderHelper argument is null. The IDataProviderHelper<T> supplies the loading/parsing strategy for the provider's data, so Create cannot construct a functional provider without it. This is the last of three fail-fast argument checks in Create.","triggerScenarios":"Calling DataProviderCreator.Create<T>(owner, resourceManager, null). Commonly caused by forgetting to instantiate the custom helper class, or an interface variable that was never assigned a concrete implementation.","commonSituations":"Implementing IDataProviderHelper<T> but forgetting to pass the instance; a field of type IDataProviderHelper<T> left null because the concrete helper was never constructed; renaming/refactoring removed the helper assignment.","solutions":["Create and pass a concrete IDataProviderHelper<T> implementation to Create<T>","Confirm the helper field/property is assigned before the Create call","If the helper is resolved dynamically, assert the resolution returned a non-null instance"],"exampleFix":"// before\nvar provider = DataProviderCreator.Create<Player>(player, resourceManager, null);\n// after\nIDataProviderHelper<Player> helper = new PlayerDataProviderHelper();\nvar provider = DataProviderCreator.Create<Player>(player, resourceManager, helper);","handlingStrategy":"validation","validationCode":"if (dataProviderHelper == null) throw new ArgumentNullException(nameof(dataProviderHelper));\nDataProviderCreator.Create<T>(owner, resourceManager, dataProviderHelper);","typeGuard":"bool HasHelper<T>(IDataProviderHelper<T> helper) => helper != null;","tryCatchPattern":"try\n{\n    var provider = DataProviderCreator.Create<T>(owner, resourceManager, helper);\n}\ncatch (GameFrameworkException ex) when (ex.Message == \"Data provider helper is invalid.\")\n{\n    // construct and pass a concrete IDataProviderHelper<T> implementation\n}","preventionTips":["Always instantiate a concrete IDataProviderHelper<T> implementation before calling Create","Initialize helper fields at declaration or in the constructor so they are never null","If the helper is resolved via DI/config, assert the resolution result is non-null"],"tags":["csharp","null-argument","gameframework","dataprovider"],"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"}