{"record":{"id":"632b4794f8bb2a2c","repo":"stride3d/stride","slug":"serializerselector","errorCode":null,"errorMessage":"serializerSelector","messagePattern":"serializerSelector","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/Serializers/RoutingSerializer.cs","lineNumber":59,"sourceCode":"// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nusing System;\n\nnamespace Stride.Core.Yaml.Serialization.Serializers\n{\n    /// <summary>\n    /// This serializer is responsible to route to a specific serializer.\n    /// </summary>\n    public class RoutingSerializer : ChainedSerializer, IYamlSerializable\n    {\n        private readonly ISerializerFactorySelector serializerSelector;\n\n        public RoutingSerializer(ISerializerFactorySelector serializerSelector)\n        {\n            if (serializerSelector == null) throw new ArgumentNullException(nameof(serializerSelector));\n            this.serializerSelector = serializerSelector;\n        }\n\n        public sealed override object ReadYaml(ref ObjectContext objectContext)\n        {\n            // If value is not null, use its TypeDescriptor otherwise use expected type descriptor\n            var instance = objectContext.Instance;\n            var typeDescriptorOfValue = instance != null ? objectContext.SerializerContext.FindTypeDescriptor(instance.GetType()) : objectContext.Descriptor;\n\n            var serializer = serializerSelector.GetSerializer(objectContext.SerializerContext, typeDescriptorOfValue);\n            return serializer.ReadYaml(ref objectContext);\n        }\n\n        public sealed override void WriteYaml(ref ObjectContext objectContext)\n        {\n            var serializer = serializerSelector.GetSerializer(objectContext.SerializerContext, objectContext.Descriptor);\n            serializer.WriteYaml(ref objectContext);\n        }","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/Serializers/RoutingSerializer.cs#L41-L77","documentation":"RoutingSerializer's constructor throws ArgumentNullException when passed a null ISerializerFactorySelector. The selector is required to route Read/WriteYaml to the appropriate serializer factory, so a null selector is rejected immediately at construction.","triggerScenarios":"new RoutingSerializer(null); passing an uninitialized selector variable; a factory chain builder that returns null for the selector.","commonSituations":"Manual YamlSerializer pipeline assembly where the settings object's SerializerFactorySelector was never set; DI container failing to resolve the selector; copy-pasted serializer setup code omitting the selector argument.","solutions":["Pass a non-null ISerializerFactorySelector instance (e.g. from SerializerSettings).","Initialize the selector before constructing RoutingSerializer.","Fix DI registration so the selector is resolvable.","Assert on the settings object earlier to surface which component produced null."],"exampleFix":"// before\nvar routing = new RoutingSerializer(null);\n// after\nvar routing = new RoutingSerializer(settings.SerializerFactorySelector);","handlingStrategy":"type-guard","validationCode":"if (selector is null) throw new InvalidOperationException(\"SerializerFactorySelector must be configured before building RoutingSerializer\");","typeGuard":"static bool HasSelector(SerializerSettings s) => s?.SerializerFactorySelector != null;","tryCatchPattern":"try { var rs = new RoutingSerializer(selector); } catch (ArgumentNullException ex) { throw new InvalidOperationException(\"RoutingSerializer requires a selector — check serializer settings initialization\", ex); }","preventionTips":["Always construct RoutingSerializer through a settings/factory helper that guarantees the selector.","Assert selector non-null in pipeline setup code.","Check DI registrations resolve ISerializerFactorySelector."],"tags":["yaml","argument-null","serializer","constructor"],"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"}