{"record":{"id":"182eb35e6149ed61","repo":"stride3d/stride","slug":"typeof-unmanagedarray-t-type-is-not-supported","errorCode":null,"errorMessage":"{ typeof(UnmanagedArray<T>) } type is not supported.","messagePattern":"(.+?) type is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/ByteHeightStickArraySource.cs","lineNumber":54,"sourceCode":"        /// The value to fill the height stick array.\n        /// </summary>\n        [DataMember(40)]\n        [DataMemberRange(0, 255, 1, 10, 0)]\n        public byte InitialByte { get; set; } = 0;\n\n        public bool IsValid() => HeightmapUtils.CheckHeightParameters(HeightStickSize, HeightType, HeightRange, HeightScale, false) &&\n            MathUtil.IsInRange(InitialByte, byte.MinValue, byte.MaxValue);\n\n        public void CopyTo<T>(UnmanagedArray<T> heightStickArray, int index) where T : struct\n        {\n            if (heightStickArray == null) throw new ArgumentNullException(nameof(heightStickArray));\n            if (heightStickArray is UnmanagedArray<byte> unmanagedArray)\n            {\n                unmanagedArray.Fill(InitialByte, index, HeightStickSize.X * HeightStickSize.Y);\n            }\n            else\n            {\n                throw new NotSupportedException($\"{ typeof(UnmanagedArray<T>) } type is not supported.\");\n            }\n        }\n\n        public bool Match(object obj)\n        {\n            var other = obj as ByteHeightStickArraySource;\n\n            if (other == null)\n            {\n                return false;\n            }\n\n            return other.HeightStickSize == HeightStickSize &&\n                other.HeightRange == HeightRange &&\n                MathF.Abs(other.HeightScale - HeightScale) < float.Epsilon &&\n                other.InitialByte == InitialByte;\n        }\n    }","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/ByteHeightStickArraySource.cs#L36-L72","documentation":"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.","triggerScenarios":"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.","commonSituations":"Reusing copy logic written for ShortHeightStickArraySource with a ByteHeightStickArraySource, or mismatching the heightfield type between source and buffer.","solutions":["Pass an UnmanagedArray<byte> destination to CopyTo","Use the matching source type (e.g. ShortHeightStickArraySource) for short/float buffers","Check HeightType when constructing the heightfield so the buffer element type matches"],"exampleFix":"// before\nUnmanagedArray<short> buffer = new UnmanagedArray<short>(w*h);\nbyteSource.CopyTo(buffer, 0);\n// after\nUnmanagedArray<byte> buffer = new UnmanagedArray<byte>(w*h);\nbyteSource.CopyTo(buffer, 0);","handlingStrategy":"type-guard","validationCode":"if (heightStickArray is UnmanagedArray<byte>)\n    byteSource.CopyTo(heightStickArray, index);","typeGuard":"bool IsByteArray(UnmanagedArray a) => a is UnmanagedArray<byte>;","tryCatchPattern":null,"preventionTips":["Match buffer element type to the height source type (byte vs short)","Check HeightType before selecting the source implementation","Avoid reusing copy helpers across source types"],"tags":["physics","heightfield","type-mismatch"],"backgroundTag":"incompatible-source-type","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}