JamesNK/Newtonsoft.Json · error · ArgumentNullException
Serialization binder cannot be null.
Error message
Serialization binder cannot be null.
What it means
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.
Source
Thrown at Src/Newtonsoft.Json/JsonSerializer.cs:129
get
{
if (_serializationBinder is SerializationBinder legacySerializationBinder)
{
return legacySerializationBinder;
}
if (_serializationBinder is SerializationBinderAdapter adapter)
{
return adapter.SerializationBinder;
}
throw new InvalidOperationException("Cannot get SerializationBinder because an ISerializationBinder was previously set.");
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value), "Serialization binder cannot be null.");
}
_serializationBinder = value as ISerializationBinder ?? new SerializationBinderAdapter(value);
}
}
/// <summary>
/// Gets or sets the <see cref="ISerializationBinder"/> used by the serializer when resolving type names.
/// </summary>
public virtual ISerializationBinder SerializationBinder
{
get => _serializationBinder;
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value), "Serialization binder cannot be null.");
}View on GitHub (pinned to 4f73e74372)
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;.
Example fix
// before serializer.Binder = null; // after serializer.SerializationBinder = DefaultSerializationBinder.Instance;
Defensive patterns
Strategy: validation
Validate before calling
serializer.Binder = (binder ?? DefaultSerializationBinder.Instance) as SerializationBinder
?? throw new ArgumentException("Use SerializationBinder property for ISerializationBinder."); Type guard
static bool IsLegacyBinder(object b) => b is SerializationBinder;
Prevention
- 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.
When it happens
Trigger: Assigning serializer.Binder = null; clearing the binder via null; DI/config supplying null for the legacy binder property.
Common situations: Migrating off the obsolete API and nulling it for 'default'; DI returning null; tests stubbing null binders.
Related errors
- Cannot get SerializationBinder because an ISerializationBind
- Cannot get SerializationBinder because an ISerializationBind
- Reference resolver cannot be null.
- array
- Could not load assembly '{0}'.
AI-assisted analysis of JamesNK/Newtonsoft.Json@4f73e74372 (2026-08-07).
Data as JSON: /api/errors/3afb1b9b56a9789a.
Report an issue: GitHub.