{"record":{"id":"87bb29a2e82cc09d","repo":"stride3d/stride","slug":"unable-to-decode-char-from-text-expecting-a-string-of-length","errorCode":null,"errorMessage":"Unable to decode char from [{text}]. Expecting a string of length == 1","messagePattern":"Unable to decode char from \\[(.+?)\\]\\. Expecting a string of length == 1","errorType":"exception","errorClass":"YamlException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/Serializers/PrimitiveSerializer.cs","lineNumber":121,"sourceCode":"                case TypeCode.String:\n                    return text;\n            }\n\n            if (type == typeof(TimeSpan))\n            {\n                return TimeSpan.Parse(text, CultureInfo.InvariantCulture);\n            }\n\n            // Remove _ character from numeric values\n            text = text.Replace(\"_\", string.Empty);\n\n            // Parse default types \n            switch (Type.GetTypeCode(type))\n            {\n                case TypeCode.Char:\n                    if (text.Length != 1)\n                    {\n                        throw new YamlException(scalar.Start, scalar.End, $\"Unable to decode char from [{text}]. Expecting a string of length == 1\");\n                    }\n                    return text.ToCharArray()[0];\n                case TypeCode.Byte:\n                    return byte.Parse(text, CultureInfo.InvariantCulture);\n                case TypeCode.SByte:\n                    return sbyte.Parse(text, CultureInfo.InvariantCulture);\n                case TypeCode.Int16:\n                    return short.Parse(text, CultureInfo.InvariantCulture);\n                case TypeCode.UInt16:\n                    return ushort.Parse(text, CultureInfo.InvariantCulture);\n                case TypeCode.Int32:\n                    return int.Parse(text, CultureInfo.InvariantCulture);\n                case TypeCode.UInt32:\n                    return uint.Parse(text, CultureInfo.InvariantCulture);\n                case TypeCode.Int64:\n                    return long.Parse(text, CultureInfo.InvariantCulture);\n                case TypeCode.UInt64:\n                    return ulong.Parse(text, CultureInfo.InvariantCulture);","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/Serializers/PrimitiveSerializer.cs#L103-L139","documentation":"PrimitiveSerializer.ConvertFrom throws this when a YAML scalar is being converted to a System.Char but the scalar text does not contain exactly one character. The YamlException includes the scalar's start/end locations. It guards the text.ToCharArray()[0] access which would otherwise fail on empty or multi-character strings.","triggerScenarios":"Deserializing a YAML scalar into a property or field whose type is char (TypeCode.Char) where the scalar value has length 0 or > 1, e.g. 'ab', an empty quoted string \"\", or a whole word assigned to a char member.","commonSituations":"Config files where a user writes a word or an empty value for a char-typed field (e.g. delimiter: none); JSON/YAML round-trips that emit multi-character strings into char slots; accidentally quoting a char in YAML so 'a' becomes a two-char string with quotes included.","solutions":["Fix the YAML source so the scalar for the char-typed member is exactly one character.","If the field should hold more text, change the property type from char to string.","Pre-validate the scalar length before conversion and emit a clearer error.","Escape/trim quotes if the value is a single character wrapped in extra quotes."],"exampleFix":"// before (YAML)\ndelimiter: none\n// after\ndelimiter: ,","handlingStrategy":"validation","validationCode":"static bool IsValidCharScalar(string text, out char value) { value = default; return text != null && text.Length == 1 && char.TryParse(text, out value); }","typeGuard":"static bool IsSingleChar(string s) => s != null && s.Length == 1;","tryCatchPattern":"try { var c = serializer.Deserialize<char>(reader); } catch (YamlException ex) { throw new FormatException($\"Char scalar at {ex.Start} must be exactly one character\", ex); }","preventionTips":["Keep char-typed fields as single-character YAML scalars, unquoted if possible.","Prefer string fields unless a single character is truly required.","Lint YAML config files for empty or multi-word values in char fields.","Round-trip test configs after schema changes."],"tags":["yaml","deserialization","char","type-conversion"],"backgroundTag":"invalid-argument-format","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"}