{"record":{"id":"fe564ede541417d0","repo":"stride3d/stride","slug":"unable-to-serialize-scalar-value-not-supported","errorCode":null,"errorMessage":"Unable to serialize scalar [{value}] not supported","messagePattern":"Unable to serialize scalar \\[(.+?)\\] not supported","errorType":"exception","errorClass":"YamlException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/Serializers/PrimitiveSerializer.cs","lineNumber":270,"sourceCode":"                        break;\n                    case TypeCode.Decimal:\n                        text = AppendDecimalPoint(((decimal) value).ToString(\"G\", CultureInfo.InvariantCulture), false);\n                        break;\n                    case TypeCode.DateTime:\n                        text = ((DateTime) value).ToString(\"o\", CultureInfo.InvariantCulture);\n                        break;\n                    default:\n                        if (valueType == typeof(TimeSpan))\n                        {\n                            text = ((TimeSpan) value).ToString(\"G\", CultureInfo.InvariantCulture);\n                        }\n                        break;\n                }\n            }\n\n            if (text == null)\n            {\n                throw new YamlException($\"Unable to serialize scalar [{value}] not supported\");\n            }\n\n            return text;\n        }\n    }\n}\n","sourceCodeStart":252,"sourceCodeEnd":277,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/Serializers/PrimitiveSerializer.cs#L252-L277","documentation":"PrimitiveSerializer.ConvertTo throws this when serializing a value whose runtime type is not one of the primitives the serializer can emit as a YAML scalar. After the type switch, if no text representation was produced, it throws a YamlException without location info.","triggerScenarios":"Serializing an object graph containing a value type that falls through the switch (unsupported enum underlying type, custom struct, null-boxed odd value, or a type the schema routed to PrimitiveSerializer incorrectly).","commonSituations":"Adding a new custom value type to a model and serializing it without registering a serializer; schema misconfiguration routing a complex type to the primitive serializer; older/newer library versions where a TypeCode is not handled.","solutions":["Register a custom IYamlSerializable/serializer factory for the unsupported type.","Change the member type to a supported primitive or string.","Check which value type reached ConvertTo and extend the type switch (if owning a fork).","Verify the serializer factory selector routes the type to the correct serializer, not PrimitiveSerializer."],"exampleFix":"// before\npublic MyCustomStruct Value { get; set; }\n// after\npublic string Value { get; set; } // or register a custom serializer","handlingStrategy":"validation","validationCode":"static bool IsYamlPrimitiveSupported(Type t) =>\n    t.IsPrimitive || t.IsEnum || t == typeof(string) || t == typeof(decimal) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(Guid);","typeGuard":null,"tryCatchPattern":"try { serializer.Serialize(writer, graph); } catch (YamlException ex) { throw new NotSupportedException($\"YAML serializer cannot encode value: {ex.Message}\", ex); }","preventionTips":["Audit model members for custom structs/value types before enabling YAML serialization.","Register a custom IYamlSerializable for every non-primitive value type.","Keep models to primitives, strings, enums, and registered types.","Test serialization of every model type in unit tests."],"tags":["yaml","serialization","scalar","unsupported-type"],"backgroundTag":"unsupported-operation","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"}