stride3d/stride · error · InvalidOperationException

The path [ ] contains non-integer index on a collection.

Error message

The path [{ToString()}] contains non-integer index on a collection.

What it means

Thrown by YamlAssetPath.ToMemberPath when a path element addressing a (non-set) collection is not an integer. IList-based collections are indexed positionally, so a string, float, or item-id style value cannot be used as the index and the conversion fails.

Solutions

  1. Edit the asset YAML to use a plain integer index for the list element
  2. Correct the code generating the path to push an int for collection (list) elements
  3. Regenerate the asset or reference so the path is rebuilt from the actual object graph
  4. Catch InvalidOperationException and report the invalid path entry to the user

Example fix

// before
path.Push(collectionDescriptor, "2");
// after
path.Push(collectionDescriptor, 2);
Defensive patterns

Strategy: validation

Validate before calling

if (isCollection && pathItem.Value is not int) throw new ArgumentException("Collection index must be an int");

Type guard

bool IsValidCollectionIndex(object v) => v is int;

Try / catch

try { memberPath = yamlPath.ToMemberPath(); } catch (InvalidOperationException ex) { log.Error($"Bad list index in '{yamlPath}': {ex.Message}"); }

Prevention

When it happens

Trigger: ToMemberPath walks into a CollectionDescriptor that is not a SetDescriptor and item.Value is not int (e.g. a string or itemId was emitted for a list index).

Common situations: YAML where a list index was serialized as a quoted number or an item-id reference; mixing list and set/identifier addressing styles when editing assets by hand; version skew between writing and reading serializers.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/3a3101eaf7bd87f8. Report an issue: GitHub.

Appendix: source

Thrown at sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs:274

                        {
                            if (collectionDescriptor is SetDescriptor setDescriptor)
                            {
                                if (item.Value is null && !collectionDescriptor.ElementType.IsNullable())
                                {
                                    throw new InvalidOperationException($"The path [{ToString()}] contains a null item on a set.");
                                }
                                if (!setDescriptor.Contains(currentObject, item.Value))
                                {
                                    throw new InvalidOperationException($"The path [{ToString()}] item doesn't exsit on a set.");
                                }
                                memberPath.Push(setDescriptor, item.Value);
                                currentObject = item.Value;
                            }
                            else
                            {
                                if (item.Value is not int)
                                {
                                    throw new InvalidOperationException($"The path [{ToString()}] contains non-integer index on a collection.");
                                }
                                memberPath.Push(collectionDescriptor, item.Value);
                                currentObject = collectionDescriptor.GetValue(currentObject, item.Value);
                            }
                        }
                        else if (typeDescriptor is DictionaryDescriptor dictionaryDescriptor)
                        {
                            if (item.Value is null) throw new InvalidOperationException($"The path [{ToString()}] contains a null key on an dictionary.");
                            memberPath.Push(dictionaryDescriptor, item.Value);
                            currentObject = dictionaryDescriptor.GetValue(currentObject, item.Value);
                        }
                        break;
                    }
                case ElementType.ItemId:
                    {
                        var ids = CollectionItemIdHelper.GetCollectionItemIds(currentObject);
                        var key = ids.GetKey(item.AsItemId());
                        var typeDescriptor = TypeDescriptorFactory.Default.Find(currentObject.GetType());

View on GitHub (pinned to 96fad776d2)