stride3d/stride · error · NotSupportedException

type is not supported.

Error message

{ typeof(UnmanagedArray<T>) } type is not supported.

What it means

ShortHeightStickArraySource.CopyTo fills a heightfield stick array with short data, but only accepts objects it can handle (UnmanagedArray<short>). If the passed heightStickArray is not such an array, the source cannot interpret it and throws NotSupportedException with a (buggy) message that prints the generic type definition instead of the runtime type.

Solutions

  1. Pass an UnmanagedArray<short> instance to CopyTo, matching the short source type
  2. Check the actual runtime type of heightStickArray; if it is short[] or another format, convert/copy it into an UnmanagedArray<short> first
  3. Use the HeightStickArraySource variant that matches your data type (byte/short/float source classes)

Example fix

// before
heightStickArraySource.CopyTo(floatArray); // wrong element type
// after
using var shortArray = new UnmanagedArray<short>(width * height);
// fill shortArray with data...
heightStickArraySource.CopyTo(shortArray);
Defensive patterns

Strategy: type-guard

Validate before calling

if (heightStickArray is not UnmanagedArray<short>)
    throw new ArgumentException($"CopyTo requires UnmanagedArray<short>, got {heightStickArray?.GetType().Name ?? "null"}");

Type guard

static bool IsShortUnmanagedArray(object obj) => obj is UnmanagedArray<short>;

Try / catch

try
{
    source.CopyTo(heightStickArray);
}
catch (NotSupportedException ex)
{
    // wrong height stick array type; convert to UnmanagedArray<short>
    logger.Error(ex, "Incompatible height stick array type");
}

Prevention

When it happens

Trigger: Calling CopyTo on a ShortHeightStickArraySource with a heightStickArray argument that fails the 'is UnmanagedArray<short>' pattern — e.g. an UnmanagedArray of a different element type, a managed array (short[]), or a differently-backed buffer.

Common situations: Passing float-based height stick data to a short heightfield source; switching heightfield storage between byte/short/float sources after a Stride version or code change; constructing the wrong HeightStickArraySource subtype for the data format at hand.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Physics/ShortHeightStickArraySource.cs:54

        /// The value to fill the height stick array.
        /// </summary>
        [DataMember(40)]
        [DataMemberRange(-32767, 32767, 1, 10, 0)]
        public short InitialShort { get; set; } = 0;

        public bool IsValid() => HeightmapUtils.CheckHeightParameters(HeightStickSize, HeightType, HeightRange, HeightScale, false) &&
            MathUtil.IsInRange(InitialShort, -short.MaxValue, short.MaxValue);

        public void CopyTo<T>(UnmanagedArray<T> heightStickArray, int index) where T : struct
        {
            if (heightStickArray == null) throw new ArgumentNullException(nameof(heightStickArray));
            if (heightStickArray is UnmanagedArray<short> unmanagedArray)
            {
                unmanagedArray.Fill(InitialShort, index, HeightStickSize.X * HeightStickSize.Y);
            }
            else
            {
                throw new NotSupportedException($"{ typeof(UnmanagedArray<T>) } type is not supported.");
            }
        }

        public bool Match(object obj)
        {
            var other = obj as ShortHeightStickArraySource;

            if (other == null)
            {
                return false;
            }

            return other.HeightStickSize == HeightStickSize &&
                other.HeightRange == HeightRange &&
                Math.Abs(other.HeightScale - HeightScale) < float.Epsilon &&
                other.InitialShort == InitialShort;
        }
    }

View on GitHub (pinned to 96fad776d2)