stride3d/stride · error · ArgumentException
Cannot specify a semantic index when using the constructor…
Error message
Cannot specify a semantic index when using the constructor with explicit semantic index. Use the implicit semantic index constructor.
What it means
The explicit-index VertexElement constructor (semanticName, semanticIndex, format) requires the semantic name to be index-free; the index is supplied separately. If the name itself matches the semantic-index pattern (e.g. "TEXCOORD0"), the constructor throws to prevent ambiguity.
Solutions
- Strip the numeric suffix from the name: new VertexElement("TEXCOORD", 0, format)
- Or keep the name indexed and drop the explicit semanticIndex argument, using the implicit constructor
Example fix
// before
new VertexElement("TEXCOORD0", 1, PixelFormat.R32G32_Float)
// after
new VertexElement("TEXCOORD", 1, PixelFormat.R32G32_Float) Defensive patterns
Strategy: validation
Validate before calling
if (Regex.IsMatch(semanticName, @"\d+$") && useExplicitIndex)
throw new ArgumentException("Strip the numeric suffix before using the explicit-index constructor"); Try / catch
try { new VertexElement(name, index, format); } catch (ArgumentException) { name = Regex.Replace(name, @"\d+$", ""); } Prevention
- Choose one constructor style per call site and stick to it
- Strip numeric suffixes when converting from FX/shader semantic strings
- Never pass both an indexed name and an explicit index
When it happens
Trigger: Calling new VertexElement("TEXCOORD0", 1, PixelFormat...) — i.e. passing an indexed semantic name together with an explicit semanticIndex argument.
Common situations: Mechanical code migration from the string-indexed constructor to the explicit-index constructor without stripping the numeric suffix; copy-paste of semantic names from FX files into the explicit overload.
Related errors
- Could not parse semantic index from the semantic name
- Duplicate s found with the same semantic name and index
- A overlaps with another element. Check the element's offset
- The 's offset and size makes it extend beyond the vertex…
- The offset of the is not a multiple of 4 bytes
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/bbc6d68fca0720d1.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/VertexElement.cs:148
/// </param>
/// <exception cref="ArgumentException">
/// <paramref name="semanticName"/> is <see langword="null"/> or an empty <see langword="string"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// Cannot specify a semantic index in the <paramref name="semanticName"/> when using this constructor.
/// Use the constructor with explicit semantic index instead (<see cref="VertexElement(string, PixelFormat)"/>).
/// </exception>
public VertexElement(string semanticName, int semanticIndex, PixelFormat format, int alignedByteOffset = AppendAligned)
: this()
{
ArgumentException.ThrowIfNullOrWhiteSpace(semanticName);
// All semantics will be upper case
semanticName = semanticName.ToUpperInvariant();
var match = MatchSemanticIndex.Match(semanticName);
if (match.Success)
throw new ArgumentException("Cannot specify a semantic index when using the constructor with explicit semantic index. Use the implicit semantic index constructor.");
// Convert to singleton string in order to speed up things
// TODO: Stale comment? Use string.Intern?
this.semanticName = semanticName;
this.semanticIndex = semanticIndex;
this.format = format;
this.alignedByteOffset = alignedByteOffset;
// Precalculate hashcode
hashCode = ComputeHashCode();
}
/// <summary>
/// Gets the HLSL semantic name associated with this element, such as <c>"POSITION"</c>, <c>"TEXCOORD"</c>, or <c>"NORMAL"</c>.
/// </summary>
/// <remarks>
/// This name must match the semantic used in the Vertex Shader input signature.View on GitHub (pinned to 96fad776d2)