{"record":{"id":"6846659799899caf","repo":"JamesNK/Newtonsoft.Json","slug":"a-member-with-the-name-0-already-exists-on-1","errorCode":null,"errorMessage":"A member with the name '{0}' already exists on '{1}'. Use the JsonPropertyAttribute to specify another name.","messagePattern":"A member with the name '(.+?)' already exists on '(.+?)'\\. Use the JsonPropertyAttribute to specify another name\\.","errorType":"exception","errorClass":"JsonSerializationException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Serialization/JsonPropertyCollection.cs","lineNumber":124,"sourceCode":"                        }\n                        if (existingProperty.DeclaringType.IsSubclassOf(property.DeclaringType)\n                            || (property.DeclaringType.IsInterface() && existingProperty.DeclaringType.ImplementInterface(property.DeclaringType)))\n                        {\n                            // current property is hidden by the existing so don't add it\n                            return;\n                        }\n                        \n                        if (_type.ImplementInterface(existingProperty.DeclaringType) && _type.ImplementInterface(property.DeclaringType))\n                        {\n                            // current property was already defined on another interface\n                            return;\n                        }\n                    }\n                }\n\n                if (duplicateProperty)\n                {\n                    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));\n                }\n            }\n\n            Add(property);\n        }\n\n        /// <summary>\n        /// Gets the closest matching <see cref=\"JsonProperty\"/> object.\n        /// First attempts to get an exact case match of <paramref name=\"propertyName\"/> and then\n        /// a case insensitive match.\n        /// </summary>\n        /// <param name=\"propertyName\">Name of the property.</param>\n        /// <returns>A matching property if found.</returns>\n        public JsonProperty? GetClosestMatchProperty(string propertyName)\n        {\n            JsonProperty? property = GetProperty(propertyName, StringComparison.Ordinal);\n            if (property == null)\n            {","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Serialization/JsonPropertyCollection.cs#L106-L142","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npublic class Model {\n    public int Data { get; set; }\n    [JsonProperty(\"data\")] public string DataValue { get; set; }\n} // both serialize to \"data\"\n// after\npublic class Model {\n    public int Data { get; set; }\n    [JsonProperty(\"dataValue\")] public string DataValue { get; set; }\n}","handlingStrategy":"validation","validationCode":"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\");","typeGuard":null,"tryCatchPattern":"try { var contract = new JsonSerializer().ContractResolver.ResolveContract(typeof(T)); }\ncatch (JsonSerializationException ex) when (ex.Message.Contains(\"already exists on\")) {\n    logger.Error(ex, \"duplicate serialized member name; add [JsonProperty]/[JsonIgnore].\"); throw;\n}","preventionTips":["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."],"tags":["contract-resolution","duplicate-property","jsonproperty","naming-strategy"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}