stride3d/stride · error · ArgumentException
Argument must be at least 2.
Error message
Argument must be at least 2.
What it means
VectorType enforces that a vector has at least 2 components (HLSL has float2..float4; there is no 0- or 1-component vector type). The record's Size property initializer throws ArgumentException when Size < 2, i.e. at construction time.
Solutions
- Ensure Size is between 2 and 4 before constructing; for a single component use the ScalarType itself instead of VectorType.
- Clamp or map size 1 (and 0) to the equivalent ScalarType in the caller.
- If the size comes from parsed data, validate/reject the input before constructing the record.
- Catch ArgumentException at the construction boundary if input sizes are user-supplied and report a diagnostic.
Example fix
// before var v = new VectorType(ScalarType.Float, 1); // ArgumentException // after SymbolType t = size >= 2 ? new VectorType(ScalarType.Float, size) : ScalarType.Float;
Defensive patterns
Strategy: validation
Validate before calling
if (size is < 2 or > 4)
throw new ArgumentOutOfRangeException(nameof(size), size, "Vector size must be 2..4");
var v = new VectorType(baseType, size); Try / catch
try { var v = new VectorType(baseType, size); }
catch (ArgumentException ex)
{
// ex.ParamName == "Size": report invalid vector dimension from parsed data
} Prevention
- Validate vector component counts (2..4) at parse time before building types.
- Represent single-component values as ScalarType, not VectorType.
- Clamp/map sizes read from external data (SPIR-V, declarations) before constructing.
When it happens
Trigger: new VectorType(scalarType, 0), new VectorType(scalarType, 1), or any negative size — including indirect paths like VectorType.From with a malformed string or SPIR-V parsing code passing a raw component count of 0/1.
Common situations: Parsing a malformed shader constant/vector declaration; SPIR-V or parser code computing vector size from data that reports 1 component (e.g. treating a scalar as a vector); hand-writing a vector type with an off-by-one size.
Related errors
- Binding describes an array larger than dataOuter
- builder
- Can't handle included both of positive and negative in type.
- Can't import symbol for
- Capacity must be a power of two
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/dca34eab6269429b.
Report an issue: GitHub.
Appendix: source
Thrown at sources/shaders/Stride.Shaders.Parsers/Core/SymbolTypes.cs:222
public static ScalarType Double { get; } = new(Scalar.Double);
public override string ToString() => Type switch
{
Scalar.Void => "void",
Scalar.Boolean => "bool",
Scalar.Int => "int",
Scalar.UInt => "uint",
Scalar.Int64 => "long",
Scalar.UInt64 => "ulong",
Scalar.Half => "half",
Scalar.Float => "float",
Scalar.Double => "double",
_ => throw new ArgumentOutOfRangeException()
};
}
public sealed partial record VectorType(ScalarType BaseType, int Size) : SymbolType()
{
public int Size { get; } = Size >= 2 ? Size : throw new ArgumentException("Argument must be at least 2.", nameof(Size));
public override string ToString() => $"{BaseType}{Size}";
}
public sealed partial record MatrixType(ScalarType BaseType, int Rows, int Columns) : SymbolType()
{
public int Rows { get; } = Rows >= 2 ? Rows : throw new ArgumentException("Argument must be at least 2.", nameof(Rows));
public int Columns { get; } = Columns >= 2 ? Columns : throw new ArgumentException("Argument must be at least 2.", nameof(Columns));
// Note: this is HLSL-style so Rows/Columns meaning is swapped
// float2x3 = OpTypeMatrix vec3 2 = MatrixType(Rows: 3, Columns: 2)
public override string ToString() => $"{BaseType}{Columns}x{Rows}";
}
/// <summary>
/// Array type.
/// </summary>
/// <param name="BaseType">The base type for the array.</param>
/// <param name="Size">The size of the array. If -1, it means size is not defined, such as using [].</param>
public sealed partial record ArrayType(SymbolType BaseType, int Size, ConstantExpression? SizeExpression = null) : SymbolType()View on GitHub (pinned to 96fad776d2)