stride3d/stride · error · SemanticErrorException

Found duplicate %YAML directive.

Error message

Found duplicate %YAML directive.

What it means

A YAML stream may declare the %YAML version directive at most once per document. When ProcessDirectives encounters a second VersionDirective token after one was already recorded, it throws SemanticErrorException pointing at the duplicate directive.

Solutions

  1. Remove the duplicate %YAML directive, keeping only one per document
  2. Emit the %YAML directive conditionally in generators (only when not already present)
  3. Deduplicate directive lines when concatenating YAML documents

Example fix

// before
%YAML 1.1
%YAML 1.1
---
// after
%YAML 1.1
---
Defensive patterns

Strategy: validation

Validate before calling

var yamlDirectives = File.ReadLines(path).Count(l => l.TrimStart().StartsWith("%YAML "));
if (yamlDirectives > 1) throw new InvalidDataException("Only one %YAML directive allowed per document");

Try / catch

try { stream.Load(reader); } catch (SemanticErrorException ex) when (ex.Message.Contains("duplicate %YAML")) { /* strip duplicates and retry */ }

Prevention

When it happens

Trigger: A single document containing two %YAML lines, e.g. "%YAML 1.1\n%YAML 1.1\n---"; or blindly concatenating directive headers when generating YAML.

Common situations: Merge scripts or templates that prepend a %YAML header to files that already have one, copy-pasted config headers.

Related errors


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

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Parser.cs:319

        }

        /// <summary>
        /// Parse directives.
        /// </summary>
        private VersionDirective ProcessDirectives(TagDirectiveCollection tags)
        {
            VersionDirective version = null;

            while (true)
            {
                VersionDirective currentVersion;
                TagDirective tag;

                if ((currentVersion = GetCurrentToken() as VersionDirective) != null)
                {
                    if (version != null)
                    {
                        throw new SemanticErrorException(currentVersion.Start, currentVersion.End, "Found duplicate %YAML directive.");
                    }

                    if (currentVersion.Version.Major != Constants.MajorVersion || currentVersion.Version.Minor != Constants.MinorVersion)
                    {
                        throw new SemanticErrorException(currentVersion.Start, currentVersion.End, "Found incompatible YAML document.");
                    }

                    version = currentVersion;
                }
                else if ((tag = GetCurrentToken() as TagDirective) != null)
                {
                    if (tagDirectives.Contains(tag.Handle))
                    {
                        throw new SemanticErrorException(tag.Start, tag.End, "Found duplicate %TAG directive.");
                    }
                    tagDirectives.Add(tag);
                    if (tags != null)
                    {

View on GitHub (pinned to 96fad776d2)