stride3d/stride · error · ArgumentNullException
stream
Error message
stream
What it means
Serializer.Deserialize(Stream, Type, ...) guards its input with a null check and throws ArgumentNullException when the stream parameter is null. It is a plain validation guard: the caller passed a null Stream, so there is nothing to deserialize.
Solutions
- Pass a valid opened Stream (e.g. File.OpenRead(path)) to Deserialize
- Check stream for null before calling and raise a file-specific error with the path
- Use the string/TextReader overloads when the content is already in memory
- Ensure asset-loading helpers throw on failure instead of returning null streams
Example fix
// before var obj = serializer.Deserialize(stream, typeof(Config)); // stream == null // after using var stream = File.OpenRead(path); var obj = serializer.Deserialize(stream, typeof(Config));
Defensive patterns
Strategy: type-guard
Validate before calling
if (stream is null) throw new FileNotFoundException("Input stream for deserialization is missing"); Type guard
static bool IsReadable(Stream s) => s != null && s.CanRead;
Try / catch
try { return serializer.Deserialize(stream, expectedType); }
catch (ArgumentNullException ex) when (ex.ParamName == "stream") { throw new InvalidOperationException("Stream was not opened before deserialization", ex); } Prevention
- Open streams with using statements right before deserializing
- Have loaders throw on failure instead of returning null streams
- Prefer file-path overloads that surface missing-file errors
- Assert stream.CanRead in tests around deserialization
When it happens
Trigger: Calling Deserialize(null, expectedType) — a stream returned null from config lookup, a File.OpenRead failure swallowed upstream, or a lazily-initialized field never assigned.
Common situations: Reading assets/config where an optional file is absent and the stream variable stays null; factory methods returning null stream on error instead of throwing.
Related errors
- ArgumentNullException: data
- ArgumentNullException: heightmap
- ArgumentNullException: paramName
- bytecode
- Can't resize VirtualFileStream if endPosition is not -1.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/868258fd06a5b750.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Serialization/Serializer.cs:255
/// </summary>
/// <param name="reader">The reader.</param>
/// <returns>A deserialized object.</returns>
public object Deserialize(TextReader reader)
{
return Deserialize(reader, null);
}
/// <summary>
/// Deserializes an object from the specified <see cref="Stream" /> with an expected specific type.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="expectedType">The expected type.</param>
/// <param name="contextSettings">The context settings.</param>
/// <returns>A deserialized object.</returns>
/// <exception cref="System.ArgumentNullException">stream</exception>
public object Deserialize(Stream stream, Type expectedType, SerializerContextSettings contextSettings = null)
{
if (stream == null) throw new ArgumentNullException(nameof(stream));
return Deserialize(new StreamReader(stream), expectedType, null, contextSettings);
}
/// <summary>
/// Deserializes an object from the specified <see cref="Stream" /> with an expected specific type.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="expectedType">The expected type.</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">stream</exception>
public object Deserialize(Stream stream, Type expectedType, SerializerContextSettings contextSettings, out SerializerContext context)
{
if (stream == null) throw new ArgumentNullException(nameof(stream));
return Deserialize(new StreamReader(stream), expectedType, null, contextSettings, out context);View on GitHub (pinned to 96fad776d2)