{"record":{"id":"cb06807886ca2ff7","repo":"restsharp/RestSharp","slug":"class-cannot-have-two-properties-marked-with-seria-cb0680","errorCode":null,"errorMessage":"Class cannot have two properties marked with SerializeAs(Content = true) attribute.","messagePattern":"Class cannot have two properties marked with SerializeAs\\(Content = true\\) attribute\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/RestSharp.Serializers.Xml/XmlSerializer.cs","lineNumber":144,"sourceCode":"\n            var propType       = prop.PropertyType;\n            var useAttribute   = false;\n            var setTextContent = false;\n            var options        = prop.GetAttribute<SerializeAsAttribute>();\n\n            if (options != null) {\n                name = options.Name.IsNotEmpty()\n                    ? options.Name\n                    : name;\n\n                name = options.TransformName(name!);\n\n                useAttribute = options.Attribute;\n\n                setTextContent = options.Content;\n\n                if (textContentAttributeAlreadyUsed && setTextContent)\n                    throw new ArgumentException(\"Class cannot have two properties marked with SerializeAs(Content = true) attribute.\");\n\n                textContentAttributeAlreadyUsed |= setTextContent;\n            }\n            else if (globalOptions != null) {\n                name = globalOptions.TransformName(name);\n            }\n\n            var nsName  = name.AsNamespaced(Namespace);\n            var element = new XElement(nsName!);\n\n            if (propType.GetTypeInfo().IsPrimitive ||\n                propType.GetTypeInfo().IsValueType ||\n                propType == typeof(string)) {\n                var value = GetSerializedValue(rawValue);\n\n                if (useAttribute) {\n                    root.Add(new XAttribute(name, value));\n                    continue;","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/restsharp/RestSharp/blob/6a5082169257438cd085f822f050d93256a8e499/src/RestSharp.Serializers.Xml/XmlSerializer.cs#L126-L162","documentation":"Thrown by the XML serializer (Serialize path) when two or more properties on the class are marked [SerializeAs(Content = true)]. Content=true designates one property as the element's text content; XML permits a single text node, so a second one is rejected during serialization.","triggerScenarios":"Serializing an object to XML (e.g. AddXmlBody or request body serialization) where the class has two properties decorated with [SerializeAs(Content = true)].","commonSituations":"Decorating multiple string properties as content intentionally (misunderstanding); copy-paste error; refactoring that duplicated the attribute.","solutions":["Remove [SerializeAs(Content = true)] from all but one property on the class.","Keep a single property as the text-content representative of the element.","Add a unit test that serializes the type to catch duplicate Content attributes early."],"exampleFix":"// before\n[SerializeAs(Content = true)] public string Text { get; set; }\n[SerializeAs(Content = true)] public string Note { get; set; }\n\n// after\n[SerializeAs(Content = true)] public string Text { get; set; }\npublic string Note { get; set; }","handlingStrategy":"validation","validationCode":"var count = typeof(T).GetProperties().Select(p => p.GetCustomAttributes(typeof(SerializeAsAttribute), false).Cast<SerializeAsAttribute>().FirstOrDefault(a => a?.Content == true)).Count(a => a != null);\nif (count > 1) throw new InvalidOperationException(\"Multiple [SerializeAs(Content=true)] properties detected\");","typeGuard":null,"tryCatchPattern":"try { request.AddXmlBody(obj); } catch (ArgumentException ex) when (ex.Message.Contains(\"two properties marked with SerializeAs(Content = true)\")) { /* remove duplicate Content attribute on the DTO */ }","preventionTips":["Keep exactly one [SerializeAs(Content = true)] per XML serializable DTO.","Unit-test XML serialization of each DTO to catch duplicate attributes."],"tags":["xml","serialization","attribute","content-mapping"],"backgroundTag":null,"analyzedSha":"6a5082169257438cd085f822f050d93256a8e499","analyzedAt":"2026-08-13T20:38:25.807Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}