{"record":{"id":"8f07baf799a84815","repo":"stride3d/stride","slug":"expecting-array-type","errorCode":null,"errorMessage":"Expecting array type","messagePattern":"Expecting array type","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Reflection/TypeDescriptors/ArrayDescriptor.cs","lineNumber":16,"sourceCode":"// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)\n// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.\n\nusing Stride.Core.Yaml.Serialization;\n\nnamespace Stride.Core.Reflection;\n\n/// <summary>\n/// A descriptor for an array.\n/// </summary>\npublic class ArrayDescriptor : CollectionBaseDescriptor\n{\n    public ArrayDescriptor(ITypeDescriptorFactory factory, Type type, bool emitDefaultValues, IMemberNamingConvention namingConvention)\n        : base(factory, type, emitDefaultValues, namingConvention)\n    {\n        if (!type.IsArray) throw new ArgumentException(\"Expecting array type\", nameof(type));\n\n        if (type.GetArrayRank() != 1)\n        {\n            throw new ArgumentException(\"Cannot support dimension [{0}] for type [{1}]. Only supporting dimension of 1\".ToFormat(type.GetArrayRank(), type.FullName));\n        }\n\n        ElementType = type.GetElementType()!;\n    }\n\n    public override DescriptorCategory Category => DescriptorCategory.Array;\n\n    /// <summary>\n    /// Gets the type of the array element.\n    /// </summary>\n    /// <value>The type of the element.</value>\n    public Type ElementType { get; }\n\n    /// <summary>","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Reflection/TypeDescriptors/ArrayDescriptor.cs#L1-L34","documentation":"ArrayDescriptor's constructor only supports array types; it validates type.IsArray and throws ArgumentException otherwise. It is thrown when the type-descriptor factory is asked to build an ArrayDescriptor for a non-array type, indicating a factory/registration mistake.","triggerScenarios":"Directly constructing new ArrayDescriptor(factory, typeof(List<int>), ...) or registering a non-array type so that ArrayDescriptor is chosen for it; a custom ITypeDescriptorFactory mapping that routes non-array types to ArrayDescriptor.","commonSituations":"Hand-wiring type descriptors instead of letting the default factory pick; type changed from T[] to List<T> in a refactor while descriptor construction code stayed the same.","solutions":["Pass an actual array type (typeof(T[]) / myInstance.GetType() when it is an array).","For List<T> or IList<T> types use ListDescriptor; for IDictionary<K,V> use DictionaryDescriptor.","If using a custom factory, fix the type-matching predicate so only array types select ArrayDescriptor."],"exampleFix":"// before\nvar desc = new ArrayDescriptor(factory, typeof(List<int>), true, namingConvention);\n// after\nvar desc = new ArrayDescriptor(factory, typeof(int[]), true, namingConvention);","handlingStrategy":"type-guard","validationCode":"if (!type.IsArray)\n    throw new ArgumentException(\"ArrayDescriptor requires an array type\", nameof(type));","typeGuard":"static bool IsArrayType(Type t) => t.IsArray;","tryCatchPattern":"try { var d = new ArrayDescriptor(factory, type, true, naming); }\ncatch (ArgumentException ex) when (ex.ParamName == \"type\") { /* pick another descriptor */ }","preventionTips":["Let the default TypeDescriptorFactory choose descriptors instead of constructing them manually.","Check Type.IsArray before selecting ArrayDescriptor in custom factories."],"tags":["type-mismatch","type-descriptor","arrays"],"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-23T08:17:48.524Z"}