stride3d/stride · error · ArgumentNullException
fromText
Error message
fromText
What it means
The string-based Deserialize overload throws ArgumentNullException("fromText") when the YAML text passed in is null. This is an up-front argument validation; it does not indicate malformed YAML, only a missing input string.
Solutions
- Ensure the YAML string is non-null before calling; use string.Empty if an empty document is intentional.
- Fix the loader that returned null (missing resource, failed read) so it throws instead.
- Guard with `if (yaml == null)` and raise an application-specific error naming the source.
- Catch ArgumentNullException to convert it into a domain error.
- Prefer loading via a stream overload with explicit file-not-found handling.
Example fix
// before
var yaml = LoadResource("config.yaml"); // returns null when missing
var cfg = (Config)serializer.Deserialize(yaml, typeof(Config));
// after
var yaml = LoadResource("config.yaml") ?? throw new FileNotFoundException("config.yaml not found");
var cfg = (Config)serializer.Deserialize(yaml, typeof(Config)); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(yaml)) throw new ArgumentException("YAML text is null or empty", nameof(yaml)); Type guard
static bool HasYamlText(string s) => !string.IsNullOrEmpty(s);
Try / catch
try { return serializer.Deserialize(yaml, typeof(Config)); }
catch (ArgumentNullException) { throw new InvalidDataException("YAML text was not loaded"); } Prevention
- Make resource loaders throw instead of returning null
- Validate strings with string.IsNullOrEmpty before deserialize
- Load files via File.ReadAllText so missing files raise FileNotFoundException
When it happens
Trigger: Calling Deserialize(string fromText, Type expectedType, object existingObject) with fromText == null, e.g. File.ReadAllText returned via a path variable that was null, or a resource loader returning null.
Common situations: Embedded resource not found and loader returns null; config file read helper swallowing errors and returning null; unit tests passing uninitialized fixture strings.
Related errors
- reader
- 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/6b030210e3ac2cb2.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Serialization/Serializer.cs:353
/// <param name="fromText">The text.</param>
/// <param name="existingObject">The object to deserialize into. If null (the default) then a new object will be created</param>
/// <returns>A deserialized object.</returns>
public object Deserialize(string fromText, object existingObject = null)
{
return Deserialize(fromText, null, existingObject);
}
/// <summary>
/// Deserializes an object from the specified string. with an expected specific type.
/// </summary>
/// <param name="fromText">From text.</param>
/// <param name="expectedType">The expected type.</param>
/// <param name="existingObject">The object to deserialize into. If null (the default) then a new object will be created</param>
/// <returns>A deserialized object.</returns>
/// <exception cref="System.ArgumentNullException">stream</exception>
public object Deserialize(string fromText, Type expectedType, object existingObject = null)
{
if (fromText == null) throw new ArgumentNullException(nameof(fromText));
return Deserialize(new StringReader(fromText), expectedType, existingObject);
}
/// <summary>
/// Deserializes an object from the specified string. with an expected specific type.
/// </summary>
/// <param name="fromText">From text.</param>
/// <param name="expectedType">The expected type.</param>
/// <param name="existingObject">The object to deserialize into. If null (the default) then a new object will be created</param>
/// <param name="context">The context used to deserialize this object.</param>
/// <returns>A deserialized object.</returns>
/// <exception cref="System.ArgumentNullException">stream</exception>
public object Deserialize(string fromText, Type expectedType, object existingObject, out SerializerContext context)
{
if (fromText == null) throw new ArgumentNullException(nameof(fromText));
return Deserialize(new StringReader(fromText), expectedType, existingObject, null, out context);
}
View on GitHub (pinned to 96fad776d2)