{"record":{"id":"eb956b02f9146a10","repo":"stride3d/stride","slug":"ex-message","errorCode":null,"errorMessage":"ex.Message","messagePattern":"ex\\.Message","errorType":"exception","errorClass":"YamlException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/Serializer.cs","lineNumber":530,"sourceCode":"\n            object result = null;\n            if (!reader.Accept<DocumentEnd>() && !reader.Accept<StreamEnd>())\n            {\n                context = new SerializerContext(this, contextSettings) {Reader = reader};\n                var node = context.Reader.Parser.Current;\n                try\n                {\n                    var objectContext = new ObjectContext(context, existingObject, context.FindTypeDescriptor(expectedType));\n                    result = context.Serializer.ObjectSerializer.ReadYaml(ref objectContext);\n                }\n                catch (YamlException)\n                {\n                    throw;\n                }\n                catch (Exception ex)\n                {\n                    ex = ex.Unwrap();\n                    throw new YamlException(node, ex);\n                }\n            }\n\n            if (hasDocumentStart)\n            {\n                reader.Expect<DocumentEnd>();\n            }\n\n            if (hasStreamStart)\n            {\n                reader.Expect<StreamEnd>();\n            }\n\n            return result;\n        }\n\n        public IYamlSerializable GetSerializer(SerializerContext context, ITypeDescriptor typeDescriptor)\n        {","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/Serializer.cs#L512-L548","documentation":"When deserialization of the current YAML node fails with an unexpected exception, Serializer.Deserialize unwraps the inner exception and rethrows it as YamlException wrapping the failing node and original exception. This is the library's generic deserialization failure: the YAML structure could not be converted into the expected type.","triggerScenarios":"Any exception thrown inside object graph construction during Deserialize — e.g. a property setter threw, a member value in YAML didn't match the target type, a constructor threw, or a custom serializer failed. Non-YamlExceptions are caught, unwrapped, and rethrown as YamlException(node, ex).","commonSituations":"YAML documents from older/newer asset versions whose fields no longer match the C# classes; typos in member names; type mismatches (string where int expected); exceptions inside object constructors during deserialization.","solutions":["Inspect the YamlException's inner exception and node path to find the offending YAML element.","Fix the YAML document to match the target type's members and value types.","Add [YamlMember(Alias=...)] or a custom serializer for renamed/changed members.","Make migration code handle old schema versions before deserializing.","Ensure constructors/property setters used during deserialization don't throw for valid deserialized states."],"exampleFix":"// before\nvar obj = serializer.Deserialize(reader, typeof(MyData)); // YamlException on unknown member\n// after\ntry\n{\n    var obj = serializer.Deserialize(reader, typeof(MyData));\n}\ncatch (YamlException ex)\n{\n    throw new InvalidOperationException($\"YAML error at {ex.Node?.Start}: {ex.InnerException?.Message}\", ex);\n}","handlingStrategy":"try-catch","validationCode":"// pre-validate document shape where possible\nif (yamlText.Contains(\"$type\") && !allowPolymorphism) throw new InvalidDataException(\"Unexpected $type reference\");","typeGuard":"static bool LooksLikeYamlObject(string s) => s != null && s.TrimStart().StartsWith(\"{\") || (s != null && s.TrimStart().StartsWith(\"-\")) || (s != null && s.Contains(':'));","tryCatchPattern":"try { return serializer.Deserialize(reader, expectedType, existingObject, settings, out ctx); }\ncatch (YamlException ex)\n{\n    // ex.Node points at the failing element; ex.InnerException has the root cause\n    throw new AssetLoadException($\"YAML deserialization failed at {ex.Node?.Start}\", ex);\n}\ncatch (Exception ex) when (ex is not YamlException) { /* already rethrown as YamlException by the library */ throw; }","preventionTips":["Keep YAML documents in sync with the C# data model; version your schemas","Add YamlMember aliases when renaming members","Avoid throwing from constructors/property setters used during deserialization","Log ex.Node.Start (line/column) to pinpoint failures","Write round-trip serialization tests for your data types"],"tags":["yaml","deserialization","type-mismatch"],"backgroundTag":"yaml-parse-error","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"}