{"record":{"id":"8f583d21a37b3863","repo":"stride3d/stride","slug":"the-path-tostring-contains-non-integer-index-on-an-array","errorCode":null,"errorMessage":"The path [{ToString()}] contains non-integer index on an array.","messagePattern":"The path \\[(.+?)\\] contains non-integer index on an array\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs","lineNumber":249,"sourceCode":"            {\n                case ElementType.Member:\n                    {\n                        var typeDescriptor = TypeDescriptorFactory.Default.Find(currentObject.GetType());\n                        var name = item.AsMember();\n                        var memberDescriptor = typeDescriptor.Members.FirstOrDefault(x => x.Name == name)\n                            ?? throw new InvalidOperationException($\"The path [{ToString()}] contains access to non-existing member [{name}].\");\n                        memberPath.Push(memberDescriptor);\n                        currentObject = memberDescriptor.Get(currentObject);\n                        break;\n                    }\n                case ElementType.Index:\n                    {\n                        var typeDescriptor = TypeDescriptorFactory.Default.Find(currentObject.GetType());\n                        if (typeDescriptor is ArrayDescriptor arrayDescriptor)\n                        {\n                            if (item.Value is not int)\n                            {\n                                throw new InvalidOperationException($\"The path [{ToString()}] contains non-integer index on an array.\");\n                            }\n                            int value = (int)item.Value;\n                            memberPath.Push(arrayDescriptor, value);\n                            currentObject = arrayDescriptor.GetValue(currentObject, value);\n                        }\n                        else if (typeDescriptor is CollectionDescriptor collectionDescriptor)\n                        {\n                            if (collectionDescriptor is SetDescriptor setDescriptor)\n                            {\n                                if (item.Value is null && !collectionDescriptor.ElementType.IsNullable())\n                                {\n                                    throw new InvalidOperationException($\"The path [{ToString()}] contains a null item on a set.\");\n                                }\n                                if (!setDescriptor.Contains(currentObject, item.Value))\n                                {\n                                    throw new InvalidOperationException($\"The path [{ToString()}] item doesn't exsit on a set.\");\n                                }\n                                memberPath.Push(setDescriptor, item.Value);","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs#L231-L267","documentation":"Thrown by YamlAssetPath.ToMemberPath when converting a serialized asset path into a MemberPath and a path element targeting an array property is not an integer. Array elements can only be addressed by integer index in Stride's property system, so the library rejects any other value type to prevent a bad cast or wrong element access later.","triggerScenarios":"Calling ToMemberPath on a YamlAssetPath whose current element is an ItemId/Index whose value is a string, float, or other non-int type while the current object's type descriptor is an ArrayDescriptor.","commonSituations":"Hand-edited or round-tripped YAML asset files where an array index was written as a quoted string (e.g. '0' instead of 0) or as a float; a serializer upgrade changing the emitted index type; code building YamlAssetPath programmatically with a long or string index.","solutions":["Open the asset .yaml file and change the array index to a bare integer (0, not '0'), or regenerate the asset path from code","Fix the code that constructs the YamlAssetPath to push an int value for array elements (e.g. (int)someLong)","Upgrade/align Stride.Core.Assets versions between the tool that wrote the YAML and the one reading it","Wrap ToMemberPath in a try/catch for InvalidOperationException and surface the offending path to the user"],"exampleFix":"// before\npath.Items.Add(new YamlAssetPath.InterfaceReference()); // or non-int index\npath.Items.Add(new YamlAssetPath.Index(\"0\"));\n// after\npath.Items.Add(new YamlAssetPath.Index(0)); // int for arrays/collections","handlingStrategy":"validation","validationCode":"if (pathItem.Value is not int) throw new ArgumentException($\"Array index must be an int, got {pathItem.Value?.GetType().Name}\");","typeGuard":"bool IsValidArrayIndex(object v) => v is int;","tryCatchPattern":"try { memberPath = yamlPath.ToMemberPath(); } catch (InvalidOperationException ex) { log.Error($\"Bad asset path '{yamlPath}': {ex.Message}\"); }","preventionTips":["Always push int values for array/collection indices when building YamlAssetPath in code","Never quote numbers in hand-edited asset YAML index positions","Keep writer and reader Stride.Core.Assets versions aligned","Log the full path string when ToMemberPath fails to speed diagnosis"],"tags":["yaml","asset-path","arrays","type-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}