stride3d/stride · error · YamlException
Unexpected parsing event found
Error message
Unexpected parsing event found [{parsingEvent}]. Expecting Scalar, Mapping or Sequence What it means
TagTypeSerializer.ReadYaml expects the next parsing event to be a NodeEvent (Scalar, MappingStart, or SequenceStart). If the peeked event is any other ParsingEvent (e.g. DocumentEnd, StreamEnd, or a collection end event), it throws this YamlException with the event's location.
Solutions
- Ensure the YAML document actually contains a value (not just '---' or comments).
- Validate the YAML structure with a standard parser before deserialization.
- Check for stray '---'/'...' markers or unbalanced flow collections in the input.
- Fix the deserialization call site so the reader starts at the beginning of the document.
Example fix
// before (file.yaml) --- --- // after key: value
Defensive patterns
Strategy: validation
Validate before calling
// Ensure document has content before deserializing
if (!yamlText.TrimStart().TrimStart('-',' ').Trim().Any(char.IsLetterOrDigit))
throw new InvalidDataException("YAML document contains no value (only markers/comments)"); Try / catch
try { return serializer.Deserialize(reader); } catch (YamlException ex) when (ex.Message.Contains("Unexpected parsing event")) { throw new InvalidDataException($"Malformed YAML at {ex.Start}: expected Scalar/Mapping/Sequence", ex); } Prevention
- Strip stray '---'/'...' markers and trailing document ends from generated YAML.
- Parse-validate with a standard YAML library before handing to the serializer.
- Keep the reader positioned at document start; do not reuse partially-consumed readers.
When it happens
Trigger: A YAML document whose structure ends unexpectedly where a node is required — e.g. a document that is just '---' with no content, trailing document markers, or a stream misaligned so a collection-end event is read as a node.
Common situations: YAML files containing only comments or a bare document start marker; concatenated/malformed multi-document streams; deserializing with the reader positioned incorrectly inside a nested structure.
Related errors
- Unable to parse input
- Multiple identifiable objects with the same id
- Unable to decode asset part reference
- Unable to deserialize reference
- Unable to find class from tag
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/55ba6a6700a8a512.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Serialization/Serializers/TagTypeSerializer.cs:68
namespace Stride.Core.Yaml.Serialization.Serializers
{
internal class TagTypeSerializer : ChainedSerializer
{
public override object ReadYaml(ref ObjectContext objectContext)
{
var parsingEvent = objectContext.Reader.Peek<ParsingEvent>();
// Can this happen here?
if (parsingEvent == null)
{
// TODO check how to put a location in this case?
throw new YamlException("Unable to parse input");
}
var node = parsingEvent as NodeEvent;
if (node == null)
{
throw new YamlException(parsingEvent.Start, parsingEvent.End, $"Unexpected parsing event found [{parsingEvent}]. Expecting Scalar, Mapping or Sequence");
}
var type = objectContext.Descriptor != null ? objectContext.Descriptor.Type : null;
// Tries to get a Type from the TagTypes
Type typeFromTag = null;
if (!string.IsNullOrEmpty(node.Tag))
{
bool remapped;
typeFromTag = objectContext.SerializerContext.TypeFromTag(node.Tag, out remapped);
if (typeFromTag == null)
{
throw new YamlException(parsingEvent.Start, parsingEvent.End, $"Unable to resolve tag [{node.Tag}] to type from tag resolution or registered assemblies");
}
// Store the fact that remap has occured on this tag
if (remapped)
{View on GitHub (pinned to 96fad776d2)