stride3d/stride · error · NotSupportedException

type is not supported.

Error message

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

What it means

ByteHeightStickArraySource.CopyTo throws NotSupportedException when the destination UnmanagedArray is not UnmanagedArray<byte>. This source writes raw byte values, so it can only fill byte-typed unmanaged arrays.

Solutions

  1. Pass an UnmanagedArray<byte> destination to CopyTo
  2. Use the matching source type (e.g. ShortHeightStickArraySource) for short/float buffers
  3. Check HeightType when constructing the heightfield so the buffer element type matches

Example fix

// before
UnmanagedArray<short> buffer = new UnmanagedArray<short>(w*h);
byteSource.CopyTo(buffer, 0);
// after
UnmanagedArray<byte> buffer = new UnmanagedArray<byte>(w*h);
byteSource.CopyTo(buffer, 0);
Defensive patterns

Strategy: type-guard

Validate before calling

if (heightStickArray is UnmanagedArray<byte>)
    byteSource.CopyTo(heightStickArray, index);

Type guard

bool IsByteArray(UnmanagedArray a) => a is UnmanagedArray<byte>;

Prevention

When it happens

Trigger: Calling CopyTo with e.g. an UnmanagedArray<short> or UnmanagedArray<float> destination — using a HeightType-compatible array of the wrong element type for this source.

Common situations: Reusing copy logic written for ShortHeightStickArraySource with a ByteHeightStickArraySource, or mismatching the heightfield type between source and buffer.

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/182eb35e6149ed61. Report an issue: GitHub.

Appendix: source

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

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

        public bool IsValid() => HeightmapUtils.CheckHeightParameters(HeightStickSize, HeightType, HeightRange, HeightScale, false) &&
            MathUtil.IsInRange(InitialByte, byte.MinValue, byte.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<byte> unmanagedArray)
            {
                unmanagedArray.Fill(InitialByte, 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 ByteHeightStickArraySource;

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

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

View on GitHub (pinned to 96fad776d2)