{"record":{"id":"361d961061f87bf8","repo":"stride3d/stride","slug":"reader","errorCode":null,"errorMessage":"reader","messagePattern":"reader","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/Serializer.cs","lineNumber":299,"sourceCode":"        /// <returns>A deserialized object.</returns>\n        /// <exception cref=\"System.ArgumentNullException\">stream</exception>\n        public T Deserialize<T>(Stream stream)\n        {\n            return (T) Deserialize(stream, typeof(T));\n        }\n\n        /// <summary>\n        /// Deserializes an object from the specified <see cref=\"TextReader\" /> with an expected specific type.\n        /// </summary>\n        /// <param name=\"reader\">The reader.</param>\n        /// <param name=\"expectedType\">The expected type.</param>\n        /// <param name=\"existingObject\">The object to deserialize into. If null (the default) then a new object will be created</param>\n        /// <param name=\"contextSettings\">The context settings.</param>\n        /// <returns>A deserialized object.</returns>\n        /// <exception cref=\"System.ArgumentNullException\">reader</exception>\n        public object Deserialize(TextReader reader, Type expectedType, object existingObject = null, SerializerContextSettings contextSettings = null)\n        {\n            if (reader == null) throw new ArgumentNullException(nameof(reader));\n            return Deserialize(new EventReader(new Parser(reader)), expectedType, existingObject, contextSettings);\n        }\n\n        /// <summary>\n        /// Deserializes an object from the specified <see cref=\"TextReader\" /> with an expected specific type.\n        /// </summary>\n        /// <param name=\"reader\">The reader.</param>\n        /// <param name=\"expectedType\">The expected type.</param>\n        /// <param name=\"existingObject\">The object to deserialize into. If null (the default) then a new object will be created</param>\n        /// <param name=\"contextSettings\">The context settings.</param>\n        /// <param name=\"context\">The context used to deserialize this object.</param>\n        /// <returns>A deserialized object.</returns>\n        /// <exception cref=\"System.ArgumentNullException\">reader</exception>\n        public object Deserialize(TextReader reader, Type expectedType, object existingObject, SerializerContextSettings contextSettings, out SerializerContext context)\n        {\n            if (reader == null) throw new ArgumentNullException(nameof(reader));\n            return Deserialize(new EventReader(new Parser(reader)), expectedType, existingObject, contextSettings, out context);\n        }","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/Serializer.cs#L281-L317","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nserializer.Deserialize(reader, typeof(Config));\n// after\nif (reader == null) throw new InvalidOperationException(\"YAML reader was not initialized\");\nserializer.Deserialize(reader, typeof(Config));","handlingStrategy":"validation","validationCode":"if (reader == null) throw new ArgumentException(\"YAML text reader must be initialized before deserialization\", nameof(reader));","typeGuard":"static bool HasReader(TextReader r) => r != null;","tryCatchPattern":"try { return serializer.Deserialize(reader, expectedType); }\ncatch (ArgumentNullException ex) { throw new InvalidOperationException(\"No YAML input reader provided\", ex); }","preventionTips":["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"],"tags":["yaml","null-argument","deserialization"],"backgroundTag":"null-argument","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"}