{"record":{"id":"a638517c2fd248e1","repo":"EllanJiang/GameFramework","slug":"resource-group-index-0-is-invalid","errorCode":null,"errorMessage":"Resource group index '{0}' is invalid.","messagePattern":"Resource group index '(.+?)' is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.ResourceGroupCollection.cs","lineNumber":47,"sourceCode":"            /// <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                }\n\n                if (resourceGroups[lastIndex] == null)\n                {\n                    throw new GameFrameworkException(Utility.Text.Format(\"Resource group index '{0}' is invalid.\", lastIndex));\n                }\n\n                m_ResourceGroups = resourceGroups;\n                m_ResourceInfos = resourceInfos;","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.ResourceGroupCollection.cs#L29-L65","documentation":"During construction, ResourceGroupCollection validates every element of the resourceGroups array. It throws GameFrameworkException(\"Resource group index '{0}' is invalid.\") when it encounters a null ResourceGroup at any index except the last (the last element is validated separately), reporting the offending index.","triggerScenarios":"Passing an array containing null entries, e.g. new ResourceGroupCollection(new ResourceGroup[] { groupA, null, groupC }, infos).","commonSituations":"Building the array from a lookup that returned null for missing group names (dictionary TryGetValue default) and never filtering nulls; hardcoded group name lists where one name was renamed or removed.","solutions":["Filter out null entries with LINQ (groups.Where(g => g != null).ToArray()) before constructing.","Fix the code that looks up groups by name so missing names are reported instead of inserting null.","Verify all requested group names exist via ResourceManager.HasResourceGroup before assembling the array."],"exampleFix":"// before\nvar groups = new ResourceGroup[] { rm.GetResourceGroup(\"UI\"), rm.GetResourceGroup(\"Deleted\") }; // second may be null\nvar col = new ResourceGroupCollection(groups, infos);\n// after\nvar groups = new[] { rm.GetResourceGroup(\"UI\"), rm.GetResourceGroup(\"Scene\") }\n    .Where(g => g != null).ToArray();\nvar col = new ResourceGroupCollection(groups, infos);","handlingStrategy":"validation","validationCode":"groups = groups.Where(g => g != null).ToArray();\nvar col = new ResourceGroupCollection(groups, infos);","typeGuard":"bool AllGroupsNonNull(ResourceGroup[] groups) => groups.All(g => g != null);","tryCatchPattern":"try { var col = new ResourceGroupCollection(groups, infos); } catch (GameFrameworkException ex) { Log.Error(ex.Message); }","preventionTips":["Always filter nulls from group arrays before use","Make group lookup methods throw or log on missing names instead of returning null","Verify group names with HasResourceGroup before lookup"],"tags":["csharp","constructor","null-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}