{"record":{"id":"7cb2f10738dcc18c","repo":"EllanJiang/GameFramework","slug":"resource-infos-is-invalid-resourcemanager","errorCode":null,"errorMessage":"Resource infos is invalid.","messagePattern":"Resource infos is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.ResourceGroupCollection.cs","lineNumber":39,"sourceCode":"            private readonly HashSet<ResourceName> m_ResourceNames;\n            private long m_TotalLength;\n            private long m_TotalCompressedLength;\n\n            /// <summary>\n            /// 初始化资源组集合的新实例。\n            /// </summary>\n            /// <param name=\"resourceGroups\">资源组集合。</param>\n            /// <param name=\"resourceInfos\">资源信息引用。</param>\n            public ResourceGroupCollection(ResourceGroup[] resourceGroups, Dictionary<ResourceName, ResourceInfo> resourceInfos)\n            {\n                if (resourceGroups == null || resourceGroups.Length < 1)\n                {\n                    throw new GameFrameworkException(\"Resource groups is invalid.\");\n                }\n\n                if (resourceInfos == null)\n                {\n                    throw new GameFrameworkException(\"Resource infos is invalid.\");\n                }\n\n                int lastIndex = resourceGroups.Length - 1;\n                for (int i = 0; i < lastIndex; i++)\n                {\n                    if (resourceGroups[i] == null)\n                    {\n                        throw new GameFrameworkException(Utility.Text.Format(\"Resource group index '{0}' is invalid.\", i));\n                    }\n\n                    for (int j = i + 1; j < resourceGroups.Length; j++)\n                    {\n                        if (resourceGroups[i] == resourceGroups[j])\n                        {\n                            throw new GameFrameworkException(Utility.Text.Format(\"Resource group '{0}' duplicated.\", resourceGroups[i].Name));\n                        }\n                    }\n                }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.ResourceGroupCollection.cs#L21-L57","documentation":"The ResourceGroupCollection constructor requires a valid Dictionary<ResourceName, ResourceInfo> reference to look up resource metadata. It throws GameFrameworkException(\"Resource infos is invalid.\") when resourceInfos is null, because every resource name aggregated from the groups must be resolved to a ResourceInfo.","triggerScenarios":"Calling new ResourceGroupCollection(groups, null) — typically the resource-info dictionary failed to load or was never populated before collection construction.","commonSituations":"Calling the constructor before ResourceManager finished building m_ResourceInfos (e.g. before InitResources/UpdateResources completed), or after a failed resource initialization left the dictionary null.","solutions":["Ensure ResourceManager resource infos are initialized (InitResources/UpdateResources completed) before constructing the collection.","Pass the manager's actual resource-info dictionary instead of a local null variable.","Guard the construction behind a null check on the dictionary and defer until it is available."],"exampleFix":"// before\nvar col = new ResourceGroupCollection(groups, null);\n// after\nif (resourceInfos == null) throw new InvalidOperationException(\"Init resources first\");\nvar col = new ResourceGroupCollection(groups, resourceInfos);","handlingStrategy":"validation","validationCode":"if (resourceInfos == null)\n    throw new InvalidOperationException(\"Resource infos not initialized; call InitResources first\");\nvar col = new ResourceGroupCollection(groups, resourceInfos);","typeGuard":"bool HasResourceInfos(Dictionary<ResourceName, ResourceInfo> infos) => infos != null && infos.Count > 0;","tryCatchPattern":"try { var col = new ResourceGroupCollection(groups, infos); } catch (GameFrameworkException ex) { Log.Error(ex.Message); }","preventionTips":["Construct collections only after resource initialization completes","Use the manager's own resource-info dictionary reference","Add an init-order assertion in bootstrap code"],"tags":["csharp","constructor","resource-management"],"backgroundTag":"invalid-constructor-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"}