stride3d/stride · error · ArgumentException

Duplicate s found with the same semantic name and index

Error message

Duplicate {nameof(VertexElement)}s found with the same semantic name and index

What it means

A validation guard in VertexElementValidator.Validate: it fires when two or more VertexElements in the input declaration share the same semantic name and semantic index. Duplicate semantics make the mapping from shader input to vertex buffer stream ambiguous, so the input layout is invalid and the validator throws ArgumentException on the elements parameter.

Solutions

  1. Increment the semantic index for repeated semantics: TEXCOORD0, TEXCOORD1, ...
  2. Remove the duplicate element if it is redundant
  3. Deduplicate elements before constructing the vertex declaration

Example fix

// before
new VertexElement("TEXCOORD", 0, PixelFormat.R32G32_Float),
new VertexElement("TEXCOORD", 0, PixelFormat.R32G32_Float)
// after
new VertexElement("TEXCOORD", 0, PixelFormat.R32G32_Float),
new VertexElement("TEXCOORD", 1, PixelFormat.R32G32_Float)
Defensive patterns

Strategy: validation

Validate before calling

bool HasDuplicates(VertexElement[] elements) =>
    elements.GroupBy(e => (e.SemanticName, e.SemanticIndex)).Any(g => g.Count() > 1);

Try / catch

try { VertexElementValidator.Validate(stride, elements); } catch (ArgumentException) { deduplicateSemantics(); }

Prevention

When it happens

Trigger: Building an element array containing duplicated (SemanticName, SemanticIndex) pairs, e.g. adding POSITION twice or two TEXCOORD entries both with index 0.

Common situations: Programmatic declaration building with a loop that doesn't increment the semantic index; merging two layout definitions that both define the same semantics.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/077d9224e0f532d8. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Graphics/VertexElementValidator.cs:100

            // Validate the element offset
            int typeSize = elements[elementIndex].Format.SizeInBytes;
            if (elementOffset == VertexElement.AppendAligned || (elementOffset + typeSize) > vertexStride)
            {
                throw new ArgumentException($"The {nameof(VertexElement)}'s offset and size makes it extend beyond the vertex stride", nameof(elements));
            }
            if ((elementOffset & 3) != 0)
            {
                throw new ArgumentException($"The offset of the {nameof(VertexElement)} is not a multiple of 4 bytes", nameof(elements));
            }

            // Check for duplicate semantic names and indices
            for (int i = 0; i < elementIndex; i++)
            {
                if (elements[elementIndex].SemanticName.Equals(elements[i].SemanticName) &&
                    elements[elementIndex].SemanticIndex == elements[i].SemanticIndex)
                {
                    throw new ArgumentException($"Duplicate {nameof(VertexElement)}s found with the same semantic name and index", nameof(elements));
                }
            }

            // Check for overlap with existing elements
            for (int i = elementOffset; i < (elementOffset + typeSize); i++)
            {
                // Check for overlap with existing elements
                if (overlapCheckArray[i] >= 0)
                {
                    throw new ArgumentException($"A {nameof(VertexElement)} overlaps with another element. Check the element's offset", nameof(elements));
                }
                // Mark this byte as occupied by this element
                overlapCheckArray[i] = elementIndex;
            }
        }
    }
}

View on GitHub (pinned to 96fad776d2)