{"record":{"id":"0f1f7c7ca857ef57","repo":"stride3d/stride","slug":"when-constructing-a-mapping-node-with-a-sequence-the-number","errorCode":null,"errorMessage":"When constructing a mapping node with a sequence, the number of elements of the sequence must be even.","messagePattern":"When constructing a mapping node with a sequence, the number of elements of the sequence must be even\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/YamlMappingNode.cs","lineNumber":173,"sourceCode":"        public YamlMappingNode(params YamlNode[] children)\n            : this((IEnumerable<YamlNode>) children)\n        {\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"YamlMappingNode\"/> class.\n        /// </summary>\n        /// <param name=\"children\">A sequence of <see cref=\"YamlNode\"/> where even elements are keys and odd elements are values.</param>\n        public YamlMappingNode(IEnumerable<YamlNode> children)\n        {\n            using (var enumerator = children.GetEnumerator())\n            {\n                while (enumerator.MoveNext())\n                {\n                    var key = enumerator.Current;\n                    if (!enumerator.MoveNext())\n                    {\n                        throw new ArgumentException(\"When constructing a mapping node with a sequence, the number of elements of the sequence must be even.\");\n                    }\n\n                    Add(key, enumerator.Current);\n                }\n            }\n        }\n\n        /// <summary>\n        /// Adds the specified mapping to the <see cref=\"Children\"/> collection.\n        /// </summary>\n        /// <param name=\"key\">The key node.</param>\n        /// <param name=\"value\">The value node.</param>\n        public void Add(YamlNode key, YamlNode value)\n        {\n            children.Add(key, value);\n        }\n\n        /// <summary>","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/YamlMappingNode.cs#L155-L191","documentation":"Thrown by YamlMappingNode's sequence constructor when a flat sequence is used to build a mapping: mappings need alternating key/value pairs, so the sequence must contain an even number of elements. The constructor walks the sequence two elements at a time (key, value) and throws when it runs out mid-pair.","triggerScenarios":"Calling the YamlMappingNode constructor (or deserializer path that uses it) with a sequence/collection whose element count is odd, e.g. a list of style entries where one entry was dropped or duplicated.","commonSituations":"Hand-editing YAML asset files so a mapping's key or value line was deleted; constructing mappings programmatically from a flattened key/value array that got out of sync.","solutions":["Check the sequence passed to the constructor and make sure its element count is even","Log or print the sequence before constructing to find the missing key or value","Fix the source YAML/data so each mapping entry has both a key and a value"],"exampleFix":"// before\nvar node = new YamlMappingNode(sequence); // sequence has 3 items\n// after\nif (sequence.Count % 2 != 0) throw new InvalidOperationException(\"Mapping sequence must have even item count\");\nvar node = new YamlMappingNode(sequence);","handlingStrategy":"validation","validationCode":"if (items == null || items.Count % 2 != 0) throw new InvalidOperationException(\"Mapping requires an even number of key/value elements\");","typeGuard":"bool IsValidMappingSequence(ICollection items) => items != null && items.Count % 2 == 0;","tryCatchPattern":"try { var node = new YamlMappingNode(sequence); } catch (ArgumentException ex) { logger.LogError(ex, \"Odd-length sequence for YAML mapping\"); }","preventionTips":["Count sequence elements before constructing a mapping node","Keep mapping data as key/value pairs rather than flat lists","Add unit tests for YAML round-tripping of hand-edited assets"],"tags":["yaml","serialization","argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}