stride3d/stride · error · ArgumentNullException
reader
Error message
reader
What it means
This ArgumentNullException is thrown by Serializer.Deserialize(TextReader, ...) when the reader parameter is null. The library validates its arguments up front before wrapping the reader in a YAML Parser/EventReader, so a null stream is detected immediately rather than deep inside parsing. It maps to the documented <exception cref="ArgumentNullException">reader</exception> contract.
Solutions
- Check the TextReader for null before calling Deserialize (or use the overload taking a string).
- Fix the upstream code that produced a null reader (file open failure, failed stream creation).
- Use the string overload Deserialize(string fromText, ...) which throws a clearer fromText ArgumentNullException for text input.
- Wrap the call in try/catch for ArgumentNullException to surface a meaningful diagnostic.
- Add a Debug.Assert or contract check at the call site to catch it during development.
Example fix
// before
serializer.Deserialize(reader, typeof(Config));
// after
if (reader == null) throw new InvalidOperationException("YAML reader was not initialized");
serializer.Deserialize(reader, typeof(Config)); Defensive patterns
Strategy: validation
Validate before calling
if (reader == null) throw new ArgumentException("YAML text reader must be initialized before deserialization", nameof(reader)); Type guard
static bool HasReader(TextReader r) => r != null;
Try / catch
try { return serializer.Deserialize(reader, expectedType); }
catch (ArgumentNullException ex) { throw new InvalidOperationException("No YAML input reader provided", ex); } Prevention
- Construct readers with `using var r = new StreamReader(path)` immediately before use
- Never let loader helpers return null readers; throw FileNotFoundException instead
- Prefer the string overload for in-memory text
- Add unit tests that assert non-null reader construction
When it happens
Trigger: Calling Serializer.Deserialize((TextReader)null, expectedType) or the overload accepting a contextSettings, with a null TextReader — typically because a file-open or stream-wrapping call returned null.
Common situations: File.Open/StreamReader constructed from a path that code assumed existed; a helper method returning null on failure; passing a field that was never initialized; refactoring that changed an out/result variable to null.
Related errors
- fromText
- 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/361d961061f87bf8.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Serialization/Serializer.cs:299
/// <returns>A deserialized object.</returns>
/// <exception cref="System.ArgumentNullException">stream</exception>
public T Deserialize<T>(Stream stream)
{
return (T) Deserialize(stream, typeof(T));
}
/// <summary>
/// Deserializes an object from the specified <see cref="TextReader" /> with an expected specific type.
/// </summary>
/// <param name="reader">The reader.</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="contextSettings">The context settings.</param>
/// <returns>A deserialized object.</returns>
/// <exception cref="System.ArgumentNullException">reader</exception>
public object Deserialize(TextReader reader, Type expectedType, object existingObject = null, SerializerContextSettings contextSettings = null)
{
if (reader == null) throw new ArgumentNullException(nameof(reader));
return Deserialize(new EventReader(new Parser(reader)), expectedType, existingObject, contextSettings);
}
/// <summary>
/// Deserializes an object from the specified <see cref="TextReader" /> with an expected specific type.
/// </summary>
/// <param name="reader">The reader.</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="contextSettings">The context settings.</param>
/// <param name="context">The context used to deserialize this object.</param>
/// <returns>A deserialized object.</returns>
/// <exception cref="System.ArgumentNullException">reader</exception>
public object Deserialize(TextReader reader, Type expectedType, object existingObject, SerializerContextSettings contextSettings, out SerializerContext context)
{
if (reader == null) throw new ArgumentNullException(nameof(reader));
return Deserialize(new EventReader(new Parser(reader)), expectedType, existingObject, contextSettings, out context);
}View on GitHub (pinned to 96fad776d2)