stride3d/stride · error · NotSupportedException
Unsupported type for GetElementType
Error message
Unsupported type for GetElementType: {symbol} What it means
GetElementType returns the underlying ScalarType of a SymbolType (scalar itself, vector's base, matrix's base). It throws NotSupportedException when the SymbolType has no single element type — e.g. arrays, structs, images, samplers, or pointers.
Solutions
- Check the type is numeric (Scalar/Vector/Matrix) before calling GetElementType.
- For arrays, recurse: the element type of an array is the element type of its base type.
- For structs, iterate members instead of asking for a single element type.
- Add explicit handling for the failing SymbolType in the calling code path.
Example fix
// before
var scalar = symbolType.GetElementType();
// after
var scalar = symbolType switch
{
ScalarType s => s,
VectorType v => v.BaseType,
MatrixType m => m.BaseType,
ArrayType a => a.BaseType.GetElementType(),
_ => throw new NotSupportedException($"No element type for {symbolType}")
}; Defensive patterns
Strategy: type-guard
Validate before calling
bool hasElementType = t is ScalarType or VectorType or MatrixType;
Type guard
static bool HasScalarElementType(SymbolType t) => t is ScalarType or VectorType or MatrixType;
Try / catch
try { var elem = symbol.GetElementType(); } catch (NotSupportedException) { /* route composite types to member-wise handling */ } Prevention
- Type-check before requesting an element type
- Recurse into arrays explicitly when needed
- Treat structs as aggregates, never single-element types
- Extend the switch when new SymbolType kinds are introduced
When it happens
Trigger: Calling GetElementType() on a non-numeric SymbolType (ArrayType, StructType, PointerType, ImageType, SamplerType) during SPIR-V type manipulation or instruction emission.
Common situations: Working with shader code that uses arrays or user-defined structs passed into helpers written for scalars/vectors/matrices, e.g. when rewriting load/store or cast instructions in the Stride shader parser.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Cannot simplify constant of type
- Unsupported type for GetElementCount
- Unsupported type for WithElementType
- Unsupported constant type
- Unsupported base type
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/c027945e9d90da05.
Report an issue: GitHub.
Appendix: source
Thrown at sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Expressions.cs:735
};
}
public static SymbolType GetVectorOrScalar(this ScalarType scalar, int size)
=> size == 1 ? scalar : new VectorType(scalar, size);
public static int GetElementCount(this SymbolType symbol) => symbol switch
{
ScalarType s => 1,
VectorType v => v.Size,
MatrixType m => m.Rows * m.Columns,
_ => throw new NotSupportedException($"Unsupported type for GetElementCount: {symbol}"),
};
public static ScalarType GetElementType(this SymbolType symbol) => symbol switch
{
ScalarType s => s,
VectorType v => v.BaseType,
MatrixType m => m.BaseType,
_ => throw new NotSupportedException($"Unsupported type for GetElementType: {symbol}"),
};
public static SymbolType WithElementType(this SymbolType symbol, ScalarType elementType) => symbol switch
{
ScalarType s => elementType,
VectorType v => v.BaseType == elementType ? v : v with { BaseType = elementType },
MatrixType m => m.BaseType == elementType ? m : m with { BaseType = elementType },
_ => throw new NotSupportedException($"Unsupported type for WithElementType: {symbol}"),
};
public static bool IsSignedInteger(this SymbolType symbol) => symbol is ScalarType { Type: Scalar.Int or Scalar.Int64 };
public static bool IsUnsignedInteger(this SymbolType symbol) => symbol is ScalarType { Type: Scalar.UInt or Scalar.UInt64 };
public static bool IsFloating(this SymbolType symbol) => symbol is ScalarType { Type: Scalar.Half or Scalar.Float or Scalar.Double };
public static bool IsInteger(this SymbolType symbol) => symbol.IsSignedInteger() || symbol.IsUnsignedInteger();
public static bool IsNumber(this SymbolType symbol) => symbol.IsInteger() || symbol.IsFloating();
public static bool IsSigned(this SymbolType symbol) => symbol.IsSignedInteger() || symbol.IsFloating();
public static bool IsUnsigned(this SymbolType symbol) => symbol.IsUnsignedInteger();
public static bool IsSignedIntegerVector(this SymbolType symbol)
=> symbol.IsSignedInteger() || symbol is VectorType v && v.BaseType.IsSignedInteger();
public static bool IsUnsignedIntegerVector(this SymbolType symbol)View on GitHub (pinned to 96fad776d2)