{"record":{"id":"4f362c52ee28e0a2","repo":"stride3d/stride","slug":"type-typeof-t-is-not-supported-as-a-symboltype","errorCode":null,"errorMessage":"Type '{typeof(T)}' is not supported as a SymbolType.","messagePattern":"Type '(.+?)' is not supported as a SymbolType\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Core/SymbolTypes.cs","lineNumber":162,"sourceCode":"            var t when t == typeof(bool) => ScalarType.From(\"bool\"),\n            var t when t == typeof(byte) => ScalarType.From(\"byte\"),\n            var t when t == typeof(sbyte) => ScalarType.From(\"sbyte\"),\n            var t when t == typeof(short) => ScalarType.From(\"short\"),\n            var t when t == typeof(ushort) => ScalarType.From(\"ushort\"),\n            var t when t == typeof(Half) => ScalarType.From(\"half\"),\n            var t when t == typeof(int) => ScalarType.From(\"int\"),\n            var t when t == typeof(uint) => ScalarType.From(\"uint\"),\n            var t when t == typeof(float) => ScalarType.From(\"float\"),\n            var t when t == typeof(double) => ScalarType.From(\"double\"),\n\n            var t when t == typeof(System.Numerics.Vector2) => VectorType.From(\"float2\"),\n            var t when t == typeof(System.Numerics.Vector3) => VectorType.From(\"float3\"),\n            var t when t == typeof(System.Numerics.Vector4) => VectorType.From(\"float4\"),\n\n            var t when t == typeof(System.Numerics.Matrix3x2) => MatrixType.From(\"float3x2\"),\n            var t when t == typeof(System.Numerics.Matrix4x4) => MatrixType.From(\"float4x4\"),\n\n            _ => throw new NotSupportedException($\"Type '{typeof(T)}' is not supported as a SymbolType.\"),\n        };\n    }\n}\n\npublic sealed partial record UndefinedType(string TypeName) : SymbolType()\n{\n    public override string ToString()\n    {\n        return TypeName;\n    }\n}\n\npublic sealed partial record PointerType(SymbolType BaseType, Specification.StorageClass StorageClass) : SymbolType()\n{\n    public override string ToId() => $\"ptr_{StorageClass}_{BaseType.ToId()}\";\n    public override string ToString() => $\"*{BaseType}\";\n}\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Core/SymbolTypes.cs#L144-L180","documentation":"SymbolType.Of<T>() maps a small fixed set of .NET primitive types (scalars, System.Numerics vectors and matrices) to their shader SymbolType equivalents. If T is any other type, the switch's default arm throws NotSupportedException. It is an internal whitelist lookup, not a general converter.","triggerScenarios":"Calling SymbolType.Of<T>() with a generic argument outside the supported set: e.g. Of<long>(), Of<Half> on platforms where it's unmapped, Of<decimal>(), Of<Vector2> from a different namespace, custom structs, or reference types like string.","commonSituations":"Developers writing generic shader-parameter binding code assume Of<T> works for any numeric type (e.g. long, decimal); refactoring a uniform struct to a type not on the whitelist; using System.Numerics analogues or user-defined vector types that are not the exact typeof(Vector3) etc.","solutions":["Use a supported T: one of void, bool, byte, sbyte, short, ushort, Half, int, uint, float, double, System.Numerics.Vector2/3/4, Matrix3x2, Matrix4x4.","If you need a custom type, construct the SymbolType directly (ScalarType, VectorType.From, MatrixType.From) instead of calling Of<T>.","If the type should legitimately be supported, add a mapping arm to SymbolType.Of<T> in SymbolTypes.cs.","Guard with a whitelist check before calling to fail fast with a clearer message."],"exampleFix":"// before\nvar t = SymbolType.Of<long>(); // NotSupportedException\n// after\nvar t = ScalarType.Int64; // 'long' maps to Scalar.Int64","handlingStrategy":"validation","validationCode":"static readonly HashSet<Type> Supported = new() {\n    typeof(void), typeof(bool), typeof(byte), typeof(sbyte),\n    typeof(short), typeof(ushort), typeof(Half), typeof(int),\n    typeof(uint), typeof(float), typeof(double),\n    typeof(System.Numerics.Vector2), typeof(System.Numerics.Vector3),\n    typeof(System.Numerics.Vector4), typeof(System.Numerics.Matrix3x2),\n    typeof(System.Numerics.Matrix4x4) };\n\nif (!Supported.Contains(typeof(T)))\n    throw new ArgumentException($\"{typeof(T)} has no SymbolType mapping\");\nvar t = SymbolType.Of<T>();","typeGuard":"static bool HasSymbolType<T>() =>\n    typeof(T) == typeof(void) || typeof(T) == typeof(bool) ||\n    typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte) ||\n    typeof(T) == typeof(short) || typeof(T) == typeof(ushort) ||\n    typeof(T) == typeof(Half) || typeof(T) == typeof(int) ||\n    typeof(T) == typeof(uint) || typeof(T) == typeof(float) ||\n    typeof(T) == typeof(double) ||\n    typeof(System.Numerics.Vector2).IsAssignableFrom(typeof(T)) ||\n    typeof(System.Numerics.Vector3).IsAssignableFrom(typeof(T)) ||\n    typeof(System.Numerics.Vector4).IsAssignableFrom(typeof(T)) ||\n    typeof(System.Numerics.Matrix3x2).IsAssignableFrom(typeof(T)) ||\n    typeof(System.Numerics.Matrix4x4).IsAssignableFrom(typeof(T));","tryCatchPattern":"try { var t = SymbolType.Of<T>(); }\ncatch (NotSupportedException ex)\n{\n    // fall back to manual SymbolType construction or report unsupported T\n}","preventionTips":["Restrict generic parameters to the documented whitelist of types via a marker interface or where-constraint comments.","Never assume numeric equivalence (long, decimal, nint) is supported.","Use exact System.Numerics types; custom vector structs will not match typeof comparisons.","Unit-test generic binding code for every T you use."],"tags":["csharp","shaders","generics","unsupported-type"],"backgroundTag":"unsupported-operation","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"}