{"record":{"id":"c4a7ba9bcad724f5","repo":"stride3d/stride","slug":"the-path-tostring-contains-a-non-valid-item-id-on-an-array","errorCode":null,"errorMessage":"The path [{ToString()}] contains a non-valid item id on an array.","messagePattern":"The path \\[(.+?)\\] contains a non-valid item id on an array\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs","lineNumber":295,"sourceCode":"                                currentObject = collectionDescriptor.GetValue(currentObject, item.Value);\n                            }\n                        }\n                        else if (typeDescriptor is DictionaryDescriptor dictionaryDescriptor)\n                        {\n                            if (item.Value is null) throw new InvalidOperationException($\"The path [{ToString()}] contains a null key on an dictionary.\");\n                            memberPath.Push(dictionaryDescriptor, item.Value);\n                            currentObject = dictionaryDescriptor.GetValue(currentObject, item.Value);\n                        }\n                        break;\n                    }\n                case ElementType.ItemId:\n                    {\n                        var ids = CollectionItemIdHelper.GetCollectionItemIds(currentObject);\n                        var key = ids.GetKey(item.AsItemId());\n                        var typeDescriptor = TypeDescriptorFactory.Default.Find(currentObject.GetType());\n                        if (typeDescriptor is ArrayDescriptor arrayDescriptor)\n                        {\n                            if (key is not int) throw new InvalidOperationException($\"The path [{ToString()}] contains a non-valid item id on an array.\");\n                            int keyInt = (int)key;\n                            memberPath.Push(arrayDescriptor, keyInt);\n                            currentObject = arrayDescriptor.GetValue(currentObject, keyInt);\n                        }\n                        else if (typeDescriptor is CollectionDescriptor collectionDescriptor)\n                        {\n                            if (collectionDescriptor.Category == DescriptorCategory.Set)\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                            }\n                            else\n                            {\n                                if (key is not int)\n                                {\n                                    throw new InvalidOperationException($\"The path [{ToString()}] contains a non-valid item id on a collection.\");","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs#L277-L313","documentation":"Thrown by YamlAssetPath.ToMemberPath when resolving an ItemId-style path element against an array but the id's key is not an integer. Arrays support only positional (int) item ids, so any other key type (string, Guid, etc.) means the stored id is corrupt or was written for a different container kind.","triggerScenarios":"In the ElementType.ItemId branch, CollectionItemIdHelper.GetCollectionItemIds(currentObject).GetKey(item.AsItemId()) returns a non-int key while the current object's descriptor is an ArrayDescriptor.","commonSituations":"Asset YAML where an array element was addressed with a GUID-style identifier (e.g. after the property was converted from a list/set to an array); corrupted or hand-edited asset files; serializer version differences in how item ids are emitted.","solutions":["Fix the asset YAML so array elements are addressed by integer index rather than a GUID item id","Regenerate the reference in the editor so a correct positional path is stored","If the property changed container type, migrate the asset to the new addressing scheme","Catch InvalidOperationException around ToMemberPath and fall back to re-linking the reference"],"exampleFix":"// before (asset yaml)\narray: !AssetRef itemId=\"d0e1...\"\n// after\narray:\n  index: 2","handlingStrategy":"type-guard","validationCode":"var key = ids.GetKey(itemId); if (key is not int) throw new ArgumentException(\"Array item ids must resolve to int keys\");","typeGuard":"bool IsIntArrayItemId(object key) => key is int;","tryCatchPattern":"try { memberPath = yamlPath.ToMemberPath(); } catch (InvalidOperationException) { RelinkReference(asset, yamlPath); }","preventionTips":["Address array elements positionally (int index), never with GUID item ids","Migrate stored paths when a property changes container type (list/set -> array)","Re-save affected assets after serializer version upgrades","Automatically re-link references whose paths fail to resolve"],"tags":["yaml","asset-path","arrays","item-id"],"backgroundTag":"invalid-identifier-format","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"}