stride3d/stride · error · ArgumentException

Cannot support dimension

Error message

Cannot support dimension [{0}] for type [{1}]. Only supporting dimension of 1

What it means

Stride's reflection layer only supports single-dimensional (rank-1) arrays in ArrayDescriptor. When the constructor sees type.GetArrayRank() != 1 — i.e. a multidimensional array like int[,] — it throws ArgumentException naming the unsupported dimension and type.

Solutions

  1. Replace multidimensional arrays with jagged arrays (int[][]) or List<List<int>>, which are supported.
  2. Flatten the array to rank-1 (T[] with computed offsets) before it reaches the serialization/descriptor layer.
  3. Implement a custom TypeDescriptor for multidimensional arrays if support is truly required.

Example fix

// before
public int[,] Grid;
// after
public int[][] Grid; // jagged array, supported by Stride serialization
Defensive patterns

Strategy: type-guard

Validate before calling

if (type.IsArray && type.GetArrayRank() != 1)
    throw new NotSupportedException("Multidimensional arrays are not supported; use jagged arrays.");

Type guard

static bool IsSupportedArray(Type t) => t.IsArray && t.GetArrayRank() == 1;

Try / catch

try { var d = new ArrayDescriptor(factory, type, true, naming); }
catch (ArgumentException ex) when (ex.Message.Contains("Only supporting dimension of 1")) { /* use jagged arrays */ }

Prevention

When it happens

Trigger: Creating an ArrayDescriptor for typeof(int[,]), typeof(string[,,]) etc., or registering a multidimensional array type with the descriptor factory.

Common situations: Serializing/deserializing models that contain rectangular or jagged multidimensional arrays; legacy data structures using T[,]; unit tests exercising arbitrary Type instances through the descriptor factory.

Related errors


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

Appendix: source

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

// 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>
    /// Creates the equivalent of list type for this array.
    /// </summary>
    /// <returns>A list type with same element type than this array.</returns>
    public Array CreateArray(int dimension)

View on GitHub (pinned to 96fad776d2)