stride3d/stride · error · YamlException
Duplicate %TAG directive.
Error message
Duplicate %TAG directive.
What it means
The YAML emitter rejects a %TAG directive that duplicates one already registered for the document. Each tag handle (e.g. !e! or !x!) may be declared only once in a document's tag directive list, so Emitter.AnalyzeTagDirective throws when AnalyzeTagDirectives sees a repeated handle and duplicates are not explicitly allowed.
Solutions
- Remove the duplicate %TAG directive so each handle appears only once per document
- Give the second directive a unique handle
- If duplicates are intentional, pass allowDuplicates=true to the directive analysis path
- Clear tagDirectives between documents (the emitter does this on document start)
Example fix
// before
var directives = new List<TagDirective> {
new TagDirective(new VersionName("!e!"), "tag:example,2000:"),
new TagDirective(new VersionName("!e!"), "tag:other:")
};
// after
var directives = new List<TagDirective> {
new TagDirective(new VersionName("!e!"), "tag:example,2000:"),
new TagDirective(new VersionName("!o!"), "tag:other:")
}; Defensive patterns
Strategy: validation
Validate before calling
bool valid = directives.GroupBy(d => d.Handle.Value).All(g => g.Count() == 1);
if (!valid) throw new InvalidOperationException("Duplicate %TAG handle in document"); Try / catch
try { emitter.Emit(docStart); }
catch (YamlException ex) when (ex.Message.Contains("Duplicate %TAG")) { /* deduplicate directives and retry */ } Prevention
- Keep one canonical TagDirective list per document
- Clear tag directives between documents
- Never merge %TAG sets from multiple inputs without deduplicating by handle
When it happens
Trigger: Calling emitter.Emit with a DocumentStart event whose TagDirectives collection contains two entries with the same handle, or emitting two documents' tag directives into the same list without clearing between documents.
Common situations: Hand-constructing YamlStream/Emitter event graphs where tag directives are appended programmatically; merging tag directive lists from multiple YAML documents; tools that copy %TAG headers from multiple source files into one output.
Related errors
- Unable to decode asset reference
- Unable to decode asset reference
- Unable to extract asset reference from object
- Unable to extract url reference from object
- Event handlers can't be added or removed after the…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/4cdebdb6c578c644.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Emitter.cs:818
isWhitespace = false;
isIndentation = false;
}
/// <summary>
/// Append a directive to the directives stack.
/// </summary>
private void AppendTagDirective(TagDirective value, bool allowDuplicates)
{
if (tagDirectives.Contains(value))
{
if (allowDuplicates)
{
return;
}
else
{
throw new YamlException("Duplicate %TAG directive.");
}
}
else
{
tagDirectives.Add(value);
}
}
/// <summary>
/// Check if a %YAML directive is valid.
/// </summary>
private static void AnalyzeVersionDirective(VersionDirective versionDirective)
{
if (versionDirective.Version.Major != Constants.MajorVersion || versionDirective.Version.Minor != Constants.MinorVersion)
{
throw new YamlException("Incompatible %YAML directive");
}
}View on GitHub (pinned to 96fad776d2)