{"record":{"id":"8098aca84ed90f2e","repo":"stride3d/stride","slug":"found-duplicate-yaml-directive","errorCode":null,"errorMessage":"Found duplicate %YAML directive.","messagePattern":"Found duplicate %YAML directive\\.","errorType":"exception","errorClass":"SemanticErrorException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Parser.cs","lineNumber":319,"sourceCode":"        }\n\n        /// <summary>\n        /// Parse directives.\n        /// </summary>\n        private VersionDirective ProcessDirectives(TagDirectiveCollection tags)\n        {\n            VersionDirective version = null;\n\n            while (true)\n            {\n                VersionDirective currentVersion;\n                TagDirective tag;\n\n                if ((currentVersion = GetCurrentToken() as VersionDirective) != null)\n                {\n                    if (version != null)\n                    {\n                        throw new SemanticErrorException(currentVersion.Start, currentVersion.End, \"Found duplicate %YAML directive.\");\n                    }\n\n                    if (currentVersion.Version.Major != Constants.MajorVersion || currentVersion.Version.Minor != Constants.MinorVersion)\n                    {\n                        throw new SemanticErrorException(currentVersion.Start, currentVersion.End, \"Found incompatible YAML document.\");\n                    }\n\n                    version = currentVersion;\n                }\n                else if ((tag = GetCurrentToken() as TagDirective) != null)\n                {\n                    if (tagDirectives.Contains(tag.Handle))\n                    {\n                        throw new SemanticErrorException(tag.Start, tag.End, \"Found duplicate %TAG directive.\");\n                    }\n                    tagDirectives.Add(tag);\n                    if (tags != null)\n                    {","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Parser.cs#L301-L337","documentation":"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.","triggerScenarios":"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.","commonSituations":"Merge scripts or templates that prepend a %YAML header to files that already have one, copy-pasted config headers.","solutions":["Remove the duplicate %YAML directive, keeping only one per document","Emit the %YAML directive conditionally in generators (only when not already present)","Deduplicate directive lines when concatenating YAML documents"],"exampleFix":"// before\n%YAML 1.1\n%YAML 1.1\n---\n// after\n%YAML 1.1\n---","handlingStrategy":"validation","validationCode":"var yamlDirectives = File.ReadLines(path).Count(l => l.TrimStart().StartsWith(\"%YAML \"));\nif (yamlDirectives > 1) throw new InvalidDataException(\"Only one %YAML directive allowed per document\");","typeGuard":null,"tryCatchPattern":"try { stream.Load(reader); } catch (SemanticErrorException ex) when (ex.Message.Contains(\"duplicate %YAML\")) { /* strip duplicates and retry */ }","preventionTips":["Emit %YAML conditionally in generators","Deduplicate directive lines when merging YAML","Lint configs before loading"],"tags":["yaml","directive","duplicate"],"backgroundTag":"yaml-parse-error","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}