{"record":{"id":"3afb1b9b56a9789a","repo":"JamesNK/Newtonsoft.Json","slug":"serialization-binder-cannot-be-null","errorCode":null,"errorMessage":"Serialization binder cannot be null.","messagePattern":"Serialization binder cannot be null\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/JsonSerializer.cs","lineNumber":129,"sourceCode":"            get\n            {\n                if (_serializationBinder is SerializationBinder legacySerializationBinder)\n                {\n                    return legacySerializationBinder;\n                }\n\n                if (_serializationBinder is SerializationBinderAdapter adapter)\n                {\n                    return adapter.SerializationBinder;\n                }\n\n                throw new InvalidOperationException(\"Cannot get SerializationBinder because an ISerializationBinder was previously set.\");\n            }\n            set\n            {\n                if (value == null)\n                {\n                    throw new ArgumentNullException(nameof(value), \"Serialization binder cannot be null.\");\n                }\n\n                _serializationBinder = value as ISerializationBinder ?? new SerializationBinderAdapter(value);\n            }\n        }\n\n        /// <summary>\n        /// Gets or sets the <see cref=\"ISerializationBinder\"/> used by the serializer when resolving type names.\n        /// </summary>\n        public virtual ISerializationBinder SerializationBinder\n        {\n            get => _serializationBinder;\n            set\n            {\n                if (value == null)\n                {\n                    throw new ArgumentNullException(nameof(value), \"Serialization binder cannot be null.\");\n                }","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/JsonSerializer.cs#L111-L147","documentation":"Thrown by the obsolete JsonSerializer.Binder setter when assigning null. The legacy SerializationBinder is required for type-name resolution during $type-polymorphic serialization; a null binder would break type binding later, so the setter fails fast with ArgumentNullException. Use the SerializationBinder (ISerializationBinder) property for new code.","triggerScenarios":"Assigning serializer.Binder = null; clearing the binder via null; DI/config supplying null for the legacy binder property.","commonSituations":"Migrating off the obsolete API and nulling it for 'default'; DI returning null; tests stubbing null binders.","solutions":["Use the non-obsolete SerializationBinder property and assign a concrete ISerializationBinder (e.g. DefaultSerializationBinder.Instance).","To reset to default behaviour, do not null the binder; create a fresh JsonSerializer or assign DefaultSerializationBinder.Instance.","Guard config/DI: serializer.Binder = binder ?? DefaultSerializationBinder.Instance;."],"exampleFix":"// before\nserializer.Binder = null;\n\n// after\nserializer.SerializationBinder = DefaultSerializationBinder.Instance;","handlingStrategy":"validation","validationCode":"serializer.Binder = (binder ?? DefaultSerializationBinder.Instance) as SerializationBinder\n    ?? throw new ArgumentException(\"Use SerializationBinder property for ISerializationBinder.\");","typeGuard":"static bool IsLegacyBinder(object b) => b is SerializationBinder;","tryCatchPattern":null,"preventionTips":["Use the non-obsolete SerializationBinder property for new code.","Never null the binder to reset; assign DefaultSerializationBinder.Instance or recreate the serializer.","Guard DI: coalesce null to a default binder."],"tags":["obsolete-api","null-argument","serialization-binder"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}