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

  1. Give one of the colliding members a distinct [JsonProperty("uniqueName")] alias.
  2. Mark the member you do not want serialized with [JsonIgnore].
  3. Refactor so the duplicate name is genuinely removed (rename the C# member).
  4. 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

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


AI-assisted analysis of JamesNK/Newtonsoft.Json@4f73e74372 (2026-08-07). Data as JSON: /api/errors/6846659799899caf. Report an issue: GitHub.