{"record":{"id":"6e8a612a57176df0","repo":"stride3d/stride","slug":"the-index-must-be-an-int-oldcollectiondescriptor","errorCode":null,"errorMessage":"The index must be an int.","messagePattern":"The index must be an int\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Reflection/TypeDescriptors/OldCollectionDescriptor.cs","lineNumber":146,"sourceCode":"        IsPureCollection = Count == 0;\n    }\n\n    public override DescriptorCategory Category => DescriptorCategory.Collection;\n\n    /// <summary>\n    /// Gets a value indicating whether this collection implements <see cref=\"IList\"/> or <see cref=\"IList{T}\"/>.\n    /// </summary>\n    public bool IsList { get; }\n\n    /// <summary>\n    /// Returns the value matching the given index in the collection.\n    /// </summary>\n    /// <param name=\"list\">The list.</param>\n    /// <param name=\"index\">The index.</param>\n    public override object? GetValue(object list, object index)\n    {\n        ArgumentNullException.ThrowIfNull(list);\n        if (index is not int) throw new ArgumentException(\"The index must be an int.\");\n        return GetValue(list, (int)index);\n    }\n\n    /// <summary>\n    /// Returns the value matching the given index in the collection.\n    /// </summary>\n    /// <param name=\"list\">The list.</param>\n    /// <param name=\"index\">The index.</param>\n    public override object? GetValue(object list, int index)\n    {\n        ArgumentNullException.ThrowIfNull(list);\n        return getIndexedItemMethod(list, index);\n    }\n\n    public override void SetValue(object list, object index, object? value)\n    {\n        ArgumentNullException.ThrowIfNull(list);\n        if (index is not int) throw new ArgumentException(\"The index must be an int.\");","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Reflection/TypeDescriptors/OldCollectionDescriptor.cs#L128-L164","documentation":"OldCollectionDescriptor.GetValue(object list, object index) mirrors ListDescriptor's boxed-index overload: it requires an int index and throws ArgumentException 'The index must be an int.' for any other boxed numeric or non-numeric type before delegating to the int overload.","triggerScenarios":"Calling OldCollectionDescriptor.GetValue(collection, index) with a boxed long/short/string index; generic enumeration code that widened indices to long.","commonSituations":"Legacy serialization/editor code paths using OldCollectionDescriptor with object-typed indices coming from dynamic APIs or 64-bit counters.","solutions":["Cast/convert the index to int before the call: GetValue(list, (int)longIndex).","Parse string indices with int.TryParse beforehand.","Prefer the int-indexed GetValue(list, int) overload directly when the index type is known."],"exampleFix":"// before\nvar v = descriptor.GetValue(collection, i as object); // i is long\n// after\nvar v = descriptor.GetValue(collection, (int)i);","handlingStrategy":"type-guard","validationCode":"if (index is int i)\n    descriptor.GetValue(collection, i);\nelse if (index is long l && l <= int.MaxValue)\n    descriptor.GetValue(collection, (int)l);","typeGuard":"static bool IsValidCollectionIndex(object? index) => index is int;","tryCatchPattern":"try { var v = descriptor.GetValue(collection, index); }\ncatch (ArgumentException ex) when (ex.Message == \"The index must be an int.\") { var v = descriptor.GetValue(collection, Convert.ToInt32(index)); }","preventionTips":["Use int indices with OldCollectionDescriptor at all times.","Coerce boxed indices to int in generic enumeration helpers.","Add a debug assert (index is int) before descriptor calls in development."],"tags":["reflection","argument","type-mismatch","csharp"],"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"}