stride3d/stride · error · YamlException
Unable to find a type for this element
Error message
Unable to find a type for this element [{node}] What it means
TagTypeSerializer.ReadYaml throws this when it cannot determine a .NET type for the node being read (type == null) and the node also has no value to infer the type from (value == null). Without a tag, descriptor type, or value, deserialization cannot proceed.
Solutions
- Add an explicit type tag to the YAML node so the serializer knows the type.
- Ensure the target property/field has a concrete declared type (not object) in the model.
- Fix alias anchors so they point to existing nodes with values.
- Check serialization output of the same model — if it emits untyped nulls it cannot read back, adjust the model or serializer settings.
Example fix
// before (YAML)
items:
-
// after
items:
- !MyApp.Item
id: 1 Defensive patterns
Strategy: validation
Validate before calling
static bool NodeIsUntypedNull(YamlNode node) => node is YamlScalarNode s && (s.Value == null || s.Value == "~") && string.IsNullOrEmpty(s.Tag);
Try / catch
try { return serializer.Deserialize(reader); } catch (YamlException ex) when (ex.Message.StartsWith("Unable to find a type")) { throw new InvalidOperationException("YAML contains an untyped null element; add a type tag or give the target member a concrete type", ex); } Prevention
- Use concrete property types instead of object in serializable models.
- Emit explicit type tags for polymorphic collection items.
- Fix dangling YAML anchors/aliases before deserializing.
- Round-trip test models to catch untyped-null emission early.
When it happens
Trigger: Deserializing a node whose type cannot be derived: no tag, no compatible expected-type descriptor, and the produced value is null — typically an aliased/untagged null node in a context where the expected type is unknown.
Common situations: YAML documents with untyped null entries in polymorphic collections; alias anchors resolving to nothing; schema configuration where the property descriptor's type was not resolved; hand-written YAML omitting tags where the library requires them.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Unable to resolve tag
- Cannot add item with key
- Cannot deserialize collection to readonly collection type
- Cannot deserialize collection to type
- Cannot instantiate an object for type
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/53fd327217343c51.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Serialization/Serializers/TagTypeSerializer.cs:131
// This allow to load any YAML documents into dictionary/list
// automatically
if ((type == null || type == typeof(object)) && value == null)
{
// If the node is a sequence start, fallback to a IList<object>
if (node is SequenceStart)
{
type = typeof(IList<object>);
}
else if (node is MappingStart)
{
// If the node is a mapping start, fallback to a IDictionary<object, object>
type = typeof(IDictionary<object, object>);
}
}
if (type == null && value == null)
{
throw new YamlException(node.Start, node.End, $"Unable to find a type for this element [{node}]");
}
if (type == null)
{
type = value.GetType();
}
else if (typeFromTag != null && value != null && value.GetType() != typeFromTag)
{
// Reset the instance if the value loaded from the tag is not of the same type then the value already instantiated
type = typeFromTag;
objectContext.Instance = null;
}
objectContext.Descriptor = objectContext.SerializerContext.FindTypeDescriptor(type);
// If this is a nullable descriptor, use its underlying type directly
if (objectContext.Descriptor is NullableDescriptor)
{View on GitHub (pinned to 96fad776d2)