{"record":{"id":"348f7c7a43ce2427","repo":"EllanJiang/GameFramework","slug":"resource-helper-is-invalid-348f7c","errorCode":null,"errorMessage":"Resource helper is invalid.","messagePattern":"Resource helper is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"critical","filePath":"GameFramework/Resource/ResourceManager.ResourceLoader.LoadResourceAgent.cs","lineNumber":54,"sourceCode":"                /// <summary>\n                /// 初始化加载资源代理的新实例。\n                /// </summary>\n                /// <param name=\"loadResourceAgentHelper\">加载资源代理辅助器。</param>\n                /// <param name=\"resourceHelper\">资源辅助器。</param>\n                /// <param name=\"resourceLoader\">加载资源器。</param>\n                /// <param name=\"readOnlyPath\">资源只读区路径。</param>\n                /// <param name=\"readWritePath\">资源读写区路径。</param>\n                /// <param name=\"decryptResourceCallback\">解密资源回调函数。</param>\n                public LoadResourceAgent(ILoadResourceAgentHelper loadResourceAgentHelper, IResourceHelper resourceHelper, ResourceLoader resourceLoader, string readOnlyPath, string readWritePath, DecryptResourceCallback decryptResourceCallback)\n                {\n                    if (loadResourceAgentHelper == null)\n                    {\n                        throw new GameFrameworkException(\"Load resource agent helper is invalid.\");\n                    }\n\n                    if (resourceHelper == null)\n                    {\n                        throw new GameFrameworkException(\"Resource helper is invalid.\");\n                    }\n\n                    if (resourceLoader == null)\n                    {\n                        throw new GameFrameworkException(\"Resource loader is invalid.\");\n                    }\n\n                    if (decryptResourceCallback == null)\n                    {\n                        throw new GameFrameworkException(\"Decrypt resource callback is invalid.\");\n                    }\n\n                    m_Helper = loadResourceAgentHelper;\n                    m_ResourceHelper = resourceHelper;\n                    m_ResourceLoader = resourceLoader;\n                    m_ReadOnlyPath = readOnlyPath;\n                    m_ReadWritePath = readWritePath;\n                    m_DecryptResourceCallback = decryptResourceCallback;","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.ResourceLoader.LoadResourceAgent.cs#L36-L72","documentation":"LoadResourceAgent requires an IResourceHelper used for resource-related lookups (e.g. checking whether a resource exists / reading metadata). A null resourceHelper means the agent cannot resolve resources, so the constructor throws this validation error.","triggerScenarios":"Constructing LoadResourceAgent (directly or via ResourceManager initialization) with null for the resourceHelper parameter — typically when the resource helper implementation was never registered with the resource module.","commonSituations":"Custom GameFramework setups replacing DefaultResourceHelper but failing to pass it into the resource initializer; wiring the helper after starting loads; copy-pasted initialization code omitting the helper argument.","solutions":["Pass a valid IResourceHelper instance (e.g. DefaultResourceHelper) when initializing the resource module.","Verify the helper is constructed before ResourceComponent/ResourceManager initialization runs.","If using a custom helper, confirm the factory/registration path actually returns a non-null instance.","Log and fail fast during bootstrap if any resource-module dependency is null."],"exampleFix":"// before\nresourceManager.Initialize(resourceMode, helper: null, ...);\n// after\nIResourceHelper resourceHelper = new DefaultResourceHelper();\nresourceManager.Initialize(resourceMode, resourceHelper, ...);","handlingStrategy":"validation","validationCode":"if (resourceHelper == null)\n    throw new ArgumentNullException(nameof(resourceHelper));\n// before init: Debug.Assert(resourceHelper != null, \"IResourceHelper must be registered\");","typeGuard":"bool IsValidResourceHelper(IResourceHelper h) => h != null;","tryCatchPattern":"try\n{\n    resourceComponent.Initialize(...);\n}\ncatch (GameFrameworkException ex) when (ex.Message.Contains(\"Resource helper\"))\n{\n    Debug.LogError(\"Register an IResourceHelper before initializing the resource module.\");\n}","preventionTips":["Register DefaultResourceHelper during bootstrap before any LoadAsset call.","Use startup assertions for all resource-module dependencies.","Keep GameFramework's ResourceComponent lifecycle intact instead of partial custom wiring.","Cover resource-module initialization with an edit-mode test that asserts no exceptions."],"tags":["gameframework","unity","null-argument","resource-loading","initialization"],"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"}