{"record":{"id":"baff0e94f3c474af","repo":"EllanJiang/GameFramework","slug":"owner-is-invalid","errorCode":null,"errorMessage":"Owner is invalid.","messagePattern":"Owner is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Base/DataProvider/DataProviderCreator.cs","lineNumber":58,"sourceCode":"        /// <typeparam name=\"T\">数据提供者的持有者的类型。</typeparam>\n        public static void FreeCachedBytes<T>()\n        {\n            DataProvider<T>.FreeCachedBytes();\n        }\n\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    }","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Base/DataProvider/DataProviderCreator.cs#L40-L76","documentation":"DataProviderCreator.Create<T>() throws GameFrameworkException('Owner is invalid.') when the owner argument passed to create a new DataProvider<T> is null. The owner is the object the data provider will belong to, and a null owner would make the provider unusable, so the factory rejects it eagerly. This is a fail-fast argument validation at the very start of Create.","triggerScenarios":"Calling GameFramework.DataProvider.DataProviderCreator.Create<T>(owner, resourceManager, dataProviderHelper) with owner == null. Typically happens when the caller's own owner field/reference has not been assigned yet (e.g. a component property accessed before initialization) or a static owner variable is still null.","commonSituations":"Calling Create from a script whose MonoBehaviour/owner reference is not yet wired in Awake; passing the result of a lookup (GetComponent, dictionary) that returned null; refactoring changed initialization order so Create runs before the owner is assigned.","solutions":["Pass a non-null owner instance to Create<T>, e.g. the game object/component that will own the data provider","Check the owner for null before calling Create and initialize it (in Awake/Start or constructor) if it is lazily assigned","Verify any lookup used to obtain the owner (GetComponent, table, service locator) actually succeeded instead of returning null"],"exampleFix":"// before\nIDataProvider<Player> provider = DataProviderCreator.Create<Player>(null, resourceManager, helper);\n// after\nif (player == null) { throw new InvalidOperationException(\"Player owner not initialized\"); }\nIDataProvider<Player> provider = DataProviderCreator.Create<Player>(player, resourceManager, helper);","handlingStrategy":"validation","validationCode":"if (owner == null) throw new ArgumentNullException(nameof(owner));\nDataProviderCreator.Create<T>(owner, resourceManager, helper);","typeGuard":"bool IsValidOwner<T>(T owner) => owner != null;","tryCatchPattern":"try\n{\n    var provider = DataProviderCreator.Create<T>(owner, resourceManager, helper);\n}\ncatch (GameFrameworkException ex) when (ex.Message == \"Owner is invalid.\")\n{\n    // log and fail fast: owner must be initialized before creating a provider\n}","preventionTips":["Assign owner references in Awake/constructor before any provider creation","Assert owner != null at the top of factory/helper methods that call Create","Avoid obtaining the owner from lookups that can silently return null without checking"],"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"}