stride3d/stride · error · ArgumentException

Expecting array type

Error message

Expecting array type

What it means

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.

Solutions

  1. Pass an actual array type (typeof(T[]) / myInstance.GetType() when it is an array).
  2. For List<T> or IList<T> types use ListDescriptor; for IDictionary<K,V> use DictionaryDescriptor.
  3. If using a custom factory, fix the type-matching predicate so only array types select ArrayDescriptor.

Example fix

// before
var desc = new ArrayDescriptor(factory, typeof(List<int>), true, namingConvention);
// after
var desc = new ArrayDescriptor(factory, typeof(int[]), true, namingConvention);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!type.IsArray)
    throw new ArgumentException("ArrayDescriptor requires an array type", nameof(type));

Type guard

static bool IsArrayType(Type t) => t.IsArray;

Try / catch

try { var d = new ArrayDescriptor(factory, type, true, naming); }
catch (ArgumentException ex) when (ex.ParamName == "type") { /* pick another descriptor */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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/8f07baf799a84815. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Reflection/TypeDescriptors/ArrayDescriptor.cs:16

// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using Stride.Core.Yaml.Serialization;

namespace Stride.Core.Reflection;

/// <summary>
/// A descriptor for an array.
/// </summary>
public class ArrayDescriptor : CollectionBaseDescriptor
{
    public ArrayDescriptor(ITypeDescriptorFactory factory, Type type, bool emitDefaultValues, IMemberNamingConvention namingConvention)
        : base(factory, type, emitDefaultValues, namingConvention)
    {
        if (!type.IsArray) throw new ArgumentException("Expecting array type", nameof(type));

        if (type.GetArrayRank() != 1)
        {
            throw new ArgumentException("Cannot support dimension [{0}] for type [{1}]. Only supporting dimension of 1".ToFormat(type.GetArrayRank(), type.FullName));
        }

        ElementType = type.GetElementType()!;
    }

    public override DescriptorCategory Category => DescriptorCategory.Array;

    /// <summary>
    /// Gets the type of the array element.
    /// </summary>
    /// <value>The type of the element.</value>
    public Type ElementType { get; }

    /// <summary>

View on GitHub (pinned to 96fad776d2)