{"record":{"id":"ae330af539378e16","repo":"stride3d/stride","slug":"type","errorCode":null,"errorMessage":"type","messagePattern":"type","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/Serializer.cs","lineNumber":203,"sourceCode":"        /// <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 };\n            context.Serializer.ObjectSerializer.WriteYaml(ref objectContext);\n            context.Writer.DocumentEnd();","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/Serializer.cs#L185-L221","documentation":"Serialize throws ArgumentNullException(\"type\") when both graph and type are null: without a graph instance the static type is the only way to pick a type descriptor, so a null type makes serialization impossible. If graph is non-null its runtime type is inferred and type may be null.","triggerScenarios":"Calling Serialize(emitter, null, null) — serializing a null graph without supplying the declared static type.","commonSituations":"Serializing possibly-null payloads (empty optional fields) without passing typeof(T); generic wrappers that forward null graph and null type.","solutions":["Pass the static type explicitly when the graph may be null: Serialize(emitter, null, typeof(MyType))","Ensure graph is non-null before serializing","In generic helpers, fall back to typeof(T) when the instance is null","Throw a clearer domain-specific error before calling Serialize when both inputs are absent"],"exampleFix":"// before\nserializer.Serialize(emitter, null, null);\n// after\nserializer.Serialize(emitter, null, typeof(MyPayload));","handlingStrategy":"type-guard","validationCode":"if (graph is null && type is null) throw new ArgumentException(\"Provide the static type when graph is null\");","typeGuard":"static bool SerializeArgsValid(object graph, Type type) => graph != null || type != null;","tryCatchPattern":"try { serializer.Serialize(emitter, graph, type); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"type\") { throw new InvalidOperationException(\"Null graph requires an explicit type\", ex); }","preventionTips":["Always pass the static type when payloads may be null","In generic wrappers, default to typeof(T)","Validate (graph, type) pairs in a shared serialize helper","Never model 'nothing to write' by passing both nulls"],"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"}