{"record":{"id":"670413c987c9e090","repo":"stride3d/stride","slug":"typeof-unmanagedarray-t-type-is-not-supported-670413","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/ShortHeightStickArraySource.cs","lineNumber":54,"sourceCode":"        /// The value to fill the height stick array.\n        /// </summary>\n        [DataMember(40)]\n        [DataMemberRange(-32767, 32767, 1, 10, 0)]\n        public short InitialShort { get; set; } = 0;\n\n        public bool IsValid() => HeightmapUtils.CheckHeightParameters(HeightStickSize, HeightType, HeightRange, HeightScale, false) &&\n            MathUtil.IsInRange(InitialShort, -short.MaxValue, short.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<short> unmanagedArray)\n            {\n                unmanagedArray.Fill(InitialShort, 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 ShortHeightStickArraySource;\n\n            if (other == null)\n            {\n                return false;\n            }\n\n            return other.HeightStickSize == HeightStickSize &&\n                other.HeightRange == HeightRange &&\n                Math.Abs(other.HeightScale - HeightScale) < float.Epsilon &&\n                other.InitialShort == InitialShort;\n        }\n    }","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/ShortHeightStickArraySource.cs#L36-L72","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass an UnmanagedArray<short> instance to CopyTo, matching the short source type","Check the actual runtime type of heightStickArray; if it is short[] or another format, convert/copy it into an UnmanagedArray<short> first","Use the HeightStickArraySource variant that matches your data type (byte/short/float source classes)"],"exampleFix":"// before\nheightStickArraySource.CopyTo(floatArray); // wrong element type\n// after\nusing var shortArray = new UnmanagedArray<short>(width * height);\n// fill shortArray with data...\nheightStickArraySource.CopyTo(shortArray);","handlingStrategy":"type-guard","validationCode":"if (heightStickArray is not UnmanagedArray<short>)\n    throw new ArgumentException($\"CopyTo requires UnmanagedArray<short>, got {heightStickArray?.GetType().Name ?? \"null\"}\");","typeGuard":"static bool IsShortUnmanagedArray(object obj) => obj is UnmanagedArray<short>;","tryCatchPattern":"try\n{\n    source.CopyTo(heightStickArray);\n}\ncatch (NotSupportedException ex)\n{\n    // wrong height stick array type; convert to UnmanagedArray<short>\n    logger.Error(ex, \"Incompatible height stick array type\");\n}","preventionTips":["Always match the HeightStickArraySource subtype (byte/short/float) to the element type of the array you pass","Use pattern matching or a small wrapper API that only accepts UnmanagedArray<short> for short sources","Inspect the source class you constructed before calling CopyTo"],"tags":["physics","heightfield","notsupported","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"}