stride3d/stride · error · YamlException

Unable to deserialize property

Error message

Unable to deserialize property [{memberName}] not found in type [{objectContext.Descriptor}]

What it means

During deserialization, a YAML key (member scalar) did not match any member of the target type. ObjectSerializer.ReadMember throws this YamlException at the offending scalar's span when TryReadMember fails to map the name to a property/field.

Solutions

  1. Fix or remove the unknown key in the YAML at the reported span
  2. Rename the YAML key to match the current property name (or add DataMember(Name=...) to restore the old name)
  3. Enable SerializerContext.AllowErrors to ignore unknown members instead of throwing
  4. Use version-tolerant members: keep [DataMember] names stable across refactors

Example fix

// before
class Model { public int Count { get; set; } }
yaml: count: 5   // lowercase, no match
// after
count -> Count  (fix the YAML key) or add [DataMember(Name = "count")]
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate YAML keys against the type
var valid = memberType.GetProperties().Select(p => p.Name)
    .Concat(memberType.GetFields().Select(f => f.Name)).ToHashSet();
var unknown = yamlKeys.Where(k => !valid.Contains(k)).ToList();
if (unknown.Any()) throw new YamlException($"Unknown members: {string.Join(",", unknown)}");

Try / catch

try
{
    serializer.Deserialize<Model>(reader);
}
catch (YamlException ex) when (ex.Message.Contains("Unable to deserialize property"))
{
    logger.LogWarning("Unknown member at {Start}-{End}: {Msg}", ex.Start, ex.End, ex.Message);
    // migrate/rename the key and retry
}

Prevention

When it happens

Trigger: A YAML key in a mapping that doesn't correspond to any property/field of the target type — renames, typos, removed members, or missing serialization metadata (DataMember attributes) after refactors.

Common situations: Renaming a C# property while old config/asset files still use the old name; serialized data produced by a newer/older assembly version; case-sensitivity mismatches; hand-edited YAML files.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/0e520af27886be98. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Serialization/Serializers/ObjectSerializer.cs:195

            while (!reader.Accept<TEnd>())
            {
                ReadMember(ref objectContext);
            }
            reader.Expect<TEnd>();
        }

        /// <summary>
        /// Reads an item of the object from the YAML flow (either a sequence item or mapping key/value item).
        /// </summary>
        /// <param name="objectContext"></param>
        /// <exception cref="YamlException">Unable to deserialize property [{0}] not found in type [{1}].DoFormat(propertyName, typeDescriptor)</exception>
        protected virtual void ReadMember(ref ObjectContext objectContext)
        {
            Scalar memberScalar;
            string memberName;
            if (!TryReadMember(ref objectContext, out memberScalar, out memberName))
            {
                throw new YamlException(memberScalar.Start, memberScalar.End, $"Unable to deserialize property [{memberName}] not found in type [{objectContext.Descriptor}]");
            }
        }

        /// <summary>
        /// Tries to read a member.
        /// </summary>
        /// <param name="objectContext">The object context.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <returns><c>true</c> if the member was successfully read, <c>false</c> otherwise.</returns>
        protected bool TryReadMember(ref ObjectContext objectContext, out string memberName)
        {
            Scalar scalar;
            return TryReadMember(ref objectContext, out scalar, out memberName);
        }

        /// <summary>
        /// Tries to read an item of the object from the YAML flow (either a sequence item or mapping key/value item).
        /// </summary>

View on GitHub (pinned to 96fad776d2)