JamesNK/Newtonsoft.Json · error · JsonSerializationException
A member with the name '{0}' already exists on '{1}'. Use th
Error message
A member with the name '{0}' already exists on '{1}'. Use the JsonPropertyAttribute to specify another name. What it means
Thrown by JsonPropertyCollection.AddProperty when a second JsonProperty with the same serialized name is added to the contract and none of the resolution rules (ignored member, derived-class hiding, interface override) apply. '{0}' is the duplicate property name and '{1}' is the contract's owning type. The message suggests JsonPropertyAttribute as the fix.
Source
Thrown at Src/Newtonsoft.Json/Serialization/JsonPropertyCollection.cs:124
}
if (existingProperty.DeclaringType.IsSubclassOf(property.DeclaringType)
|| (property.DeclaringType.IsInterface() && existingProperty.DeclaringType.ImplementInterface(property.DeclaringType)))
{
// current property is hidden by the existing so don't add it
return;
}
if (_type.ImplementInterface(existingProperty.DeclaringType) && _type.ImplementInterface(property.DeclaringType))
{
// current property was already defined on another interface
return;
}
}
}
if (duplicateProperty)
{
throw new JsonSerializationException("A member with the name '{0}' already exists on '{1}'. Use the JsonPropertyAttribute to specify another name.".FormatWith(CultureInfo.InvariantCulture, property.PropertyName, _type));
}
}
Add(property);
}
/// <summary>
/// Gets the closest matching <see cref="JsonProperty"/> object.
/// First attempts to get an exact case match of <paramref name="propertyName"/> and then
/// a case insensitive match.
/// </summary>
/// <param name="propertyName">Name of the property.</param>
/// <returns>A matching property if found.</returns>
public JsonProperty? GetClosestMatchProperty(string propertyName)
{
JsonProperty? property = GetProperty(propertyName, StringComparison.Ordinal);
if (property == null)
{View on GitHub (pinned to 4f73e74372)
Solutions
- Give one of the colliding members a distinct [JsonProperty("uniqueName")] alias.
- Mark the member you do not want serialized with [JsonIgnore].
- Refactor so the duplicate name is genuinely removed (rename the C# member).
- If caused by a NamingStrategy, make the two source members distinct enough that the strategy cannot collapse them.
Example fix
// before
public class Model {
public int Data { get; set; }
[JsonProperty("data")] public string DataValue { get; set; }
} // both serialize to "data"
// after
public class Model {
public int Data { get; set; }
[JsonProperty("dataValue")] public string DataValue { get; set; }
} Defensive patterns
Strategy: validation
Validate before calling
var names = type.GetMembers().Select(m => resolver.GetResolvedPropertyName(m.Name)); if (names.GroupBy(n=>n).Any(g=>g.Count()>1)) throw new InvalidOperationException("duplicate serialized names"); Try / catch
try { var contract = new JsonSerializer().ContractResolver.ResolveContract(typeof(T)); }
catch (JsonSerializationException ex) when (ex.Message.Contains("already exists on")) {
logger.Error(ex, "duplicate serialized member name; add [JsonProperty]/[JsonIgnore]."); throw;
} Prevention
- Run a contract-resolution unit test that asserts unique serialized names per type.
- Use distinct [JsonProperty] aliases when a NamingStrategy would collapse names.
- [JsonIgnore] members you don't want serialized.
- Avoid applying DataMember and JsonProperty with conflicting names.
When it happens
Trigger: Two members on the same type serialize to the same name: e.g. a field and property with identical names after camelCase naming, a base and derived property that don't form a proper override/hiding relationship, explicit interface implementations that collide, or a [JsonProperty("name")] that duplicates another member's serialized name.
Common situations: Applying a NamingStrategy (CamelCasePropertyNamesContractResolver) that collapses two distinct PascalCase members to one name; adding [JsonProperty] aliases that collide; mixing DataMember(Name=...) with JsonProperty; multiple interface members mapping to one name; a newtonsoft version upgrade that changed member-discovery ordering.
Related errors
- type
- Invalid extension data attribute on '{0}'. Member '{1}' must
- Invalid extension data attribute on '{0}'. Member '{1}' type
- Multiple constructors with the JsonConstructorAttribute.
- Constructor for '{0}' must have no parameters or a single pa
AI-assisted analysis of JamesNK/Newtonsoft.Json@4f73e74372 (2026-08-07).
Data as JSON: /api/errors/6846659799899caf.
Report an issue: GitHub.