{"record":{"id":"0d67b2aa66357f8e","repo":"stride3d/stride","slug":"emitter","errorCode":null,"errorMessage":"emitter","messagePattern":"emitter","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/Serializer.cs","lineNumber":201,"sourceCode":"        /// Serializes the specified object.\n        /// </summary>\n        /// <param name=\"emitter\">The <see cref=\"IEmitter\" /> where to serialize the object.</param>\n        /// <param name=\"graph\">The object to serialize.</param>\n        public void Serialize(IEmitter emitter, object graph)\n        {\n            Serialize(emitter, graph, graph == null ? typeof(object) : null);\n        }\n\n        /// <summary>\n        /// Serializes the specified object.\n        /// </summary>\n        /// <param name=\"emitter\">The <see cref=\"IEmitter\" /> where to serialize the object.</param>\n        /// <param name=\"graph\">The object to serialize.</param>\n        /// <param name=\"type\">The static type of the object to serialize.</param>\n        /// <param name=\"contextSettings\">The context settings.</param>\n        public void Serialize(IEmitter emitter, object graph, Type type, SerializerContextSettings contextSettings = null)\n        {\n            if (emitter == null) throw new ArgumentNullException(nameof(emitter));\n\n            if (graph == null && type == null) throw new ArgumentNullException(nameof(type));\n\n            // Configure the emitter\n            // TODO the current emitter is not enough configurable to format its output\n            // This should be improved\n            var defaultEmitter = emitter as Emitter;\n            if (defaultEmitter != null)\n            {\n                defaultEmitter.ForceIndentLess = Settings.IndentLess;\n            }\n\n            var context = new SerializerContext(this, contextSettings) { Emitter = emitter, Writer = CreateEmitter(emitter) };\n\n            // Serialize the document\n            context.Writer.StreamStart();\n            context.Writer.DocumentStart();\n            var objectContext = new ObjectContext(context, graph, context.FindTypeDescriptor(type)) { Style = DataStyle.Any };","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/Serializer.cs#L183-L219","documentation":"Serializer.Serialize validates its IEmitter argument and throws ArgumentNullException(\"emitter\") when null. The emitter is the output sink for serialization, so there is nothing meaningful to do without it.","triggerScenarios":"Calling Serialize(null, graph, type) — e.g. an emitter variable that failed to initialize from a file/stream that could not be opened, or a method returning null emitter.","commonSituations":"Conditional emitter creation where output setup failed silently; refactors that removed emitter instantiation; DI containers returning null for IEmitter.","solutions":["Pass a constructed emitter (e.g. new Emitter(writer)) to Serialize","Create the emitter from a validated TextWriter/Stream before calling Serialize","Guard the emitter creation path so it never returns null (throw earlier with context)","Use the string Serialize overloads that build the emitter internally"],"exampleFix":"// before\nserializer.Serialize(emitter, graph, type); // emitter == null\n// after\nusing var writer = new StreamWriter(path);\nserializer.Serialize(new Emitter(writer), graph, type);","handlingStrategy":"type-guard","validationCode":"if (emitter is null) throw new ArgumentNullException(nameof(emitter));","typeGuard":"static bool CanSerialize(IEmitter e) => e != null;","tryCatchPattern":"try { serializer.Serialize(emitter, graph, type); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"emitter\") { throw new InvalidOperationException(\"Emitter not initialized\", ex); }","preventionTips":["Construct emitters with using/var immediately before use","Avoid optional emitter parameters that default to null","Return TextWriter/Stream from helpers, never null","Wrap Serialize calls in a helper that validates inputs once"],"tags":["argument-null","serialization","csharp"],"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"}