{"record":{"id":"bbc6d68fca0720d1","repo":"stride3d/stride","slug":"cannot-specify-a-semantic-index-when-using-the-constructor","errorCode":null,"errorMessage":"Cannot specify a semantic index when using the constructor with explicit semantic index. Use the implicit semantic index constructor.","messagePattern":"Cannot specify a semantic index when using the constructor with explicit semantic index\\. Use the implicit semantic index constructor\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/VertexElement.cs","lineNumber":148,"sourceCode":"    /// </param>\n    /// <exception cref=\"ArgumentException\">\n    ///   <paramref name=\"semanticName\"/> is <see langword=\"null\"/> or an empty <see langword=\"string\"/>.\n    /// </exception>\n    /// <exception cref=\"ArgumentException\">\n    ///   Cannot specify a semantic index in the <paramref name=\"semanticName\"/> when using this constructor.\n    ///   Use the constructor with explicit semantic index instead (<see cref=\"VertexElement(string, PixelFormat)\"/>).\n    /// </exception>\n    public VertexElement(string semanticName, int semanticIndex, PixelFormat format, int alignedByteOffset = AppendAligned)\n        : this()\n    {\n        ArgumentException.ThrowIfNullOrWhiteSpace(semanticName);\n\n        // All semantics will be upper case\n        semanticName = semanticName.ToUpperInvariant();\n\n        var match = MatchSemanticIndex.Match(semanticName);\n        if (match.Success)\n            throw new ArgumentException(\"Cannot specify a semantic index when using the constructor with explicit semantic index. Use the implicit semantic index constructor.\");\n\n        // Convert to singleton string in order to speed up things\n        // TODO: Stale comment? Use string.Intern?\n        this.semanticName = semanticName;\n        this.semanticIndex = semanticIndex;\n        this.format = format;\n        this.alignedByteOffset = alignedByteOffset;\n\n        // Precalculate hashcode\n        hashCode = ComputeHashCode();\n    }\n\n\n    /// <summary>\n    ///   Gets the HLSL semantic name associated with this element, such as <c>\"POSITION\"</c>, <c>\"TEXCOORD\"</c>, or <c>\"NORMAL\"</c>.\n    /// </summary>\n    /// <remarks>\n    ///   This name must match the semantic used in the Vertex Shader input signature.","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/VertexElement.cs#L130-L166","documentation":"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.","triggerScenarios":"Calling new VertexElement(\"TEXCOORD0\", 1, PixelFormat...) — i.e. passing an indexed semantic name together with an explicit semanticIndex argument.","commonSituations":"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.","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"],"exampleFix":"// before\nnew VertexElement(\"TEXCOORD0\", 1, PixelFormat.R32G32_Float)\n// after\nnew VertexElement(\"TEXCOORD\", 1, PixelFormat.R32G32_Float)","handlingStrategy":"validation","validationCode":"if (Regex.IsMatch(semanticName, @\"\\d+$\") && useExplicitIndex)\n    throw new ArgumentException(\"Strip the numeric suffix before using the explicit-index constructor\");","typeGuard":null,"tryCatchPattern":"try { new VertexElement(name, index, format); } catch (ArgumentException) { name = Regex.Replace(name, @\"\\d+$\", \"\"); }","preventionTips":["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"],"tags":["graphics","vertex-declaration","semantic","mutually-exclusive-arguments"],"backgroundTag":"mutually-exclusive-options","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"}