{"record":{"id":"557941039a254653","repo":"stride3d/stride","slug":"unexpected-null-scalar-value","errorCode":null,"errorMessage":"Unexpected null scalar value","messagePattern":"Unexpected null scalar value","errorType":"exception","errorClass":"YamlException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/Serializers/PrimitiveSerializer.cs","lineNumber":78,"sourceCode":"\n        public override object ConvertFrom(ref ObjectContext context, Scalar scalar)\n        {\n            var primitiveType = (PrimitiveDescriptor) context.Descriptor;\n            var type = primitiveType.Type;\n            var text = scalar.Value;\n\n            // Return null if expected type is an object and scalar is null\n            if (text == null)\n            {\n                switch (Type.GetTypeCode(type))\n                {\n                    case TypeCode.Object:\n                    case TypeCode.Empty:\n                    case TypeCode.String:\n                        return null;\n                    default:\n                        // TODO check this\n                        throw new YamlException(scalar.Start, scalar.End, \"Unexpected null scalar value\");\n                }\n            }\n\n            // If type is an enum, try to parse it\n            if (type.IsEnum)\n            {\n                bool enumRemapped;\n                var result = primitiveType.ParseEnum(text, out enumRemapped);\n                if (enumRemapped)\n                {\n                    context.SerializerContext.HasRemapOccurred = true;\n                }\n                return result;\n            }\n\n            // Parse default types \n            switch (Type.GetTypeCode(type))\n            {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/Serializers/PrimitiveSerializer.cs#L60-L96","documentation":"PrimitiveSerializer.ConvertFrom encountered a null scalar for a target type whose TypeCode is not Object/Empty/String/nullable — i.e. a value type like int, bool, or DateTime. There is no sensible null representation, so this YamlException is thrown.","triggerScenarios":"A YAML node contains 'null'/'~'/empty scalar but the conversion target is a non-nullable primitive (int, double, bool, enum-backed non-object typecodes). ConvertFrom reaches the default branch and throws.","commonSituations":"YAML file where a numeric field is left empty or set to null; schema change making a formerly-string property a primitive; tools writing '~' for missing values.","solutions":["Provide a concrete value in the YAML for the primitive field instead of null/empty","Make the target property nullable (int?, bool?) or use a default value strategy","Pre-process the YAML to replace null scalars with defaults before deserialization","Enable AllowErrors if skipping such members is acceptable"],"exampleFix":"// before\nport: null   // property is int\n// after\nport: 8080   // or change property to int? Port { get; set; }","handlingStrategy":"type-guard","validationCode":"if (scalar == null || scalar.Value == null || scalar.Value is \"\" or \"~\" or \"null\")\n{\n    if (targetType.IsValueType && Nullable.GetUnderlyingType(targetType) == null)\n        throw new YamlException(scalar?.Start, scalar?.End, $\"{targetType} cannot be null; provide a value\");\n}","typeGuard":"static bool AcceptsNull(Type t) =>\n    !t.IsValueType || Nullable.GetUnderlyingType(t) != null || t == typeof(object) || t == typeof(string);","tryCatchPattern":"try\n{\n    primitiveSerializer.ReadYaml(ref objectContext);\n}\ncatch (YamlException ex) when (ex.Message == \"Unexpected null scalar value\")\n{\n    // substitute a default value or make the member nullable\n}","preventionTips":["Never leave non-nullable primitive fields empty in YAML files","Use nullable types (int?, double?) where absence is meaningful","Pre-process documents to map null/~ to sensible defaults"],"tags":["yaml","deserialization","null-value","primitive"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}