{"record":{"id":"077d9224e0f532d8","repo":"stride3d/stride","slug":"duplicate-nameof-vertexelement-s-found-with-the-same","errorCode":null,"errorMessage":"Duplicate {nameof(VertexElement)}s found with the same semantic name and index","messagePattern":"Duplicate (.+?)s found with the same semantic name and index","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/VertexElementValidator.cs","lineNumber":100,"sourceCode":"\n            // Validate the element offset\n            int typeSize = elements[elementIndex].Format.SizeInBytes;\n            if (elementOffset == VertexElement.AppendAligned || (elementOffset + typeSize) > vertexStride)\n            {\n                throw new ArgumentException($\"The {nameof(VertexElement)}'s offset and size makes it extend beyond the vertex stride\", nameof(elements));\n            }\n            if ((elementOffset & 3) != 0)\n            {\n                throw new ArgumentException($\"The offset of the {nameof(VertexElement)} is not a multiple of 4 bytes\", nameof(elements));\n            }\n\n            // Check for duplicate semantic names and indices\n            for (int i = 0; i < elementIndex; i++)\n            {\n                if (elements[elementIndex].SemanticName.Equals(elements[i].SemanticName) &&\n                    elements[elementIndex].SemanticIndex == elements[i].SemanticIndex)\n                {\n                    throw new ArgumentException($\"Duplicate {nameof(VertexElement)}s found with the same semantic name and index\", nameof(elements));\n                }\n            }\n\n            // Check for overlap with existing elements\n            for (int i = elementOffset; i < (elementOffset + typeSize); i++)\n            {\n                // Check for overlap with existing elements\n                if (overlapCheckArray[i] >= 0)\n                {\n                    throw new ArgumentException($\"A {nameof(VertexElement)} overlaps with another element. Check the element's offset\", nameof(elements));\n                }\n                // Mark this byte as occupied by this element\n                overlapCheckArray[i] = elementIndex;\n            }\n        }\n    }\n}\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/VertexElementValidator.cs#L82-L118","documentation":"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.","triggerScenarios":"Building an element array containing duplicated (SemanticName, SemanticIndex) pairs, e.g. adding POSITION twice or two TEXCOORD entries both with index 0.","commonSituations":"Programmatic declaration building with a loop that doesn't increment the semantic index; merging two layout definitions that both define the same semantics.","solutions":["Increment the semantic index for repeated semantics: TEXCOORD0, TEXCOORD1, ...","Remove the duplicate element if it is redundant","Deduplicate elements before constructing the vertex declaration"],"exampleFix":"// before\nnew VertexElement(\"TEXCOORD\", 0, PixelFormat.R32G32_Float),\nnew VertexElement(\"TEXCOORD\", 0, PixelFormat.R32G32_Float)\n// after\nnew VertexElement(\"TEXCOORD\", 0, PixelFormat.R32G32_Float),\nnew VertexElement(\"TEXCOORD\", 1, PixelFormat.R32G32_Float)","handlingStrategy":"validation","validationCode":"bool HasDuplicates(VertexElement[] elements) =>\n    elements.GroupBy(e => (e.SemanticName, e.SemanticIndex)).Any(g => g.Count() > 1);","typeGuard":null,"tryCatchPattern":"try { VertexElementValidator.Validate(stride, elements); } catch (ArgumentException) { deduplicateSemantics(); }","preventionTips":["Increment semantic indices for repeated semantics","Deduplicate element lists when merging layouts","Track used (name, index) pairs in a set while building declarations"],"tags":["graphics","vertex-declaration","duplicate","semantic"],"backgroundTag":"schema-validation-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}