stride3d/stride · error · YamlException
Unable to serialize scalar
Error message
Unable to serialize scalar [{value}] not supported What it means
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.
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.
Example fix
// before
public MyCustomStruct Value { get; set; }
// after
public string Value { get; set; } // or register a custom serializer Defensive patterns
Strategy: validation
Validate before calling
static bool IsYamlPrimitiveSupported(Type t) =>
t.IsPrimitive || t.IsEnum || t == typeof(string) || t == typeof(decimal) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(Guid); Try / catch
try { serializer.Serialize(writer, graph); } catch (YamlException ex) { throw new NotSupportedException($"YAML serializer cannot encode value: {ex.Message}", ex); } Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Multi-dimensional arrays are not supported.
- Unable to decode asset reference
- Unable to decode asset reference
- Unable to extract asset reference from object
- Unable to extract url reference from object
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/fe564ede541417d0.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Serialization/Serializers/PrimitiveSerializer.cs:270
break;
case TypeCode.Decimal:
text = AppendDecimalPoint(((decimal) value).ToString("G", CultureInfo.InvariantCulture), false);
break;
case TypeCode.DateTime:
text = ((DateTime) value).ToString("o", CultureInfo.InvariantCulture);
break;
default:
if (valueType == typeof(TimeSpan))
{
text = ((TimeSpan) value).ToString("G", CultureInfo.InvariantCulture);
}
break;
}
}
if (text == null)
{
throw new YamlException($"Unable to serialize scalar [{value}] not supported");
}
return text;
}
}
}
View on GitHub (pinned to 96fad776d2)