{"record":{"id":"f2521275740069bc","repo":"stride3d/stride","slug":"duplicate-key","errorCode":null,"errorMessage":"Duplicate key","messagePattern":"Duplicate key","errorType":"exception","errorClass":"YamlException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/YamlMappingNode.cs","lineNumber":95,"sourceCode":"        internal YamlMappingNode(EventReader events, DocumentLoadingState state)\n        {\n            MappingStart mapping = events.Expect<MappingStart>();\n            Load(mapping, state);\n            Style = mapping.Style;\n\n            bool hasUnresolvedAliases = false;\n            while (!events.Accept<MappingEnd>())\n            {\n                YamlNode key = ParseNode(events, state);\n                YamlNode value = ParseNode(events, state);\n\n                try\n                {\n                    children.Add(key, value);\n                }\n                catch (ArgumentException err)\n                {\n                    throw new YamlException(key.Start, key.End, \"Duplicate key\", err);\n                }\n\n                hasUnresolvedAliases |= key is YamlAliasNode || value is YamlAliasNode;\n            }\n\n            if (hasUnresolvedAliases)\n            {\n                state.AddNodeWithUnresolvedAliases(this);\n            }\n#if DEBUG\n            else\n            {\n                foreach (var child in children)\n                {\n                    if (child.Key is YamlAliasNode)\n                    {\n                        throw new InvalidOperationException(\"Error in alias resolution.\");\n                    }","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/YamlMappingNode.cs#L77-L113","documentation":"YamlMappingNode's constructor throws this while building the mapping when adding a child whose key already exists (children.Add raises ArgumentException, converted to a YamlException positioned at the duplicate key node). YAML technically allows duplicate keys but this library treats them as invalid.","triggerScenarios":"Loading a YAML mapping that contains the same key twice at the same level, e.g. 'name: a' followed by 'name: b'; duplicate keys generated by templating or by concatenating config files.","commonSituations":"Merged/concatenated YAML config files where both halves define the same key; hand-edited YAML with an accidental repeated key; generated YAML (template loops) emitting the same key multiple times; strict parsing after migration from a laxer YAML tool.","solutions":["Remove or rename the duplicate key in the YAML file — the exception location points at the second occurrence.","Use YAML merge keys (<<: *anchor) instead of duplicating keys when combining sections.","Add a pre-parse lint check (yamllint with duplicate-key rule) to CI.","Fix the generator/template that emits the YAML so keys are unique."],"exampleFix":"// before\nname: first\nname: second\n// after\nname: second","handlingStrategy":"validation","validationCode":"// Detect duplicate top-level keys before loading (example with YamlDotNet-style scanner)\nvar keys = new HashSet<string>();\nforeach (var key in EnumerateMappingKeys(yamlText))\n    if (!keys.Add(key)) throw new InvalidDataException($\"Duplicate YAML key '{key}'\");","typeGuard":null,"tryCatchPattern":"try { return YamlMappingNode.FromEvents(events); } catch (YamlException ex) when (ex.Message == \"Duplicate key\") { throw new InvalidDataException($\"Duplicate mapping key at {ex.Start}; remove or rename the repeated key\", ex); }","preventionTips":["Run yamllint (duplicate-key rule) on YAML in CI.","Never concatenate YAML config files; use merge keys or hierarchical loading.","Check templating/generator output for repeated keys.","Enable strict duplicate-key handling in all YAML tooling."],"tags":["yaml","duplicate-key","mapping","parse"],"backgroundTag":"schema-validation-failed","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"}