{"record":{"id":"4cdebdb6c578c644","repo":"stride3d/stride","slug":"duplicate-tag-directive","errorCode":null,"errorMessage":"Duplicate %TAG directive.","messagePattern":"Duplicate %TAG directive\\.","errorType":"exception","errorClass":"YamlException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Emitter.cs","lineNumber":818,"sourceCode":"\n            isWhitespace = false;\n            isIndentation = false;\n        }\n\n        /// <summary>\n        /// Append a directive to the directives stack.\n        /// </summary>\n        private void AppendTagDirective(TagDirective value, bool allowDuplicates)\n        {\n            if (tagDirectives.Contains(value))\n            {\n                if (allowDuplicates)\n                {\n                    return;\n                }\n                else\n                {\n                    throw new YamlException(\"Duplicate %TAG directive.\");\n                }\n            }\n            else\n            {\n                tagDirectives.Add(value);\n            }\n        }\n\n        /// <summary>\n        /// Check if a %YAML directive is valid.\n        /// </summary>\n        private static void AnalyzeVersionDirective(VersionDirective versionDirective)\n        {\n            if (versionDirective.Version.Major != Constants.MajorVersion || versionDirective.Version.Minor != Constants.MinorVersion)\n            {\n                throw new YamlException(\"Incompatible %YAML directive\");\n            }\n        }","sourceCodeStart":800,"sourceCodeEnd":836,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Emitter.cs#L800-L836","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\nvar directives = new List<TagDirective> {\n  new TagDirective(new VersionName(\"!e!\"), \"tag:example,2000:\"),\n  new TagDirective(new VersionName(\"!e!\"), \"tag:other:\")\n};\n// after\nvar directives = new List<TagDirective> {\n  new TagDirective(new VersionName(\"!e!\"), \"tag:example,2000:\"),\n  new TagDirective(new VersionName(\"!o!\"), \"tag:other:\")\n};","handlingStrategy":"validation","validationCode":"bool valid = directives.GroupBy(d => d.Handle.Value).All(g => g.Count() == 1);\nif (!valid) throw new InvalidOperationException(\"Duplicate %TAG handle in document\");","typeGuard":null,"tryCatchPattern":"try { emitter.Emit(docStart); }\ncatch (YamlException ex) when (ex.Message.Contains(\"Duplicate %TAG\")) { /* deduplicate directives and retry */ }","preventionTips":["Keep one canonical TagDirective list per document","Clear tag directives between documents","Never merge %TAG sets from multiple inputs without deduplicating by handle"],"tags":["yaml","serialization","emitter"],"backgroundTag":"duplicate-tag-directive","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}