{"record":{"id":"f2ff3a89ca3f155e","repo":"restsharp/RestSharp","slug":"class-cannot-have-two-properties-marked-with-seria","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/XmlDeserializer.cs","lineNumber":123,"sourceCode":"\n            if (!typeIsPublic || !prop.CanWrite)\n                continue;\n\n            var    deserializeFromContent   = false;\n            var    isNameDefinedInAttribute = false;\n            XName? name                     = null;\n            var    attributes               = prop.GetCustomAttributes(typeof(DeserializeAsAttribute), false);\n\n            if (attributes.Any()) {\n                var attribute = (DeserializeAsAttribute)attributes.First();\n\n                name                     = attribute.Name.AsNamespaced(Namespace);\n                isNameDefinedInAttribute = !string.IsNullOrEmpty(name?.LocalName);\n\n                deserializeFromContent = attribute.Content;\n\n                if (deserializeFromContentAttributeAlreadyUsed && deserializeFromContent)\n                    throw new ArgumentException(\"Class cannot have two properties marked with SerializeAs(Content = true) attribute.\");\n\n                deserializeFromContentAttributeAlreadyUsed |= deserializeFromContent;\n            }\n\n            if (name == null) name = prop.Name.AsNamespaced(Namespace);\n\n            var value = GetValueFromXml(root, name, prop, isNameDefinedInAttribute);\n\n            if (value == null) {\n                // special case for text content node\n                if (deserializeFromContent) {\n                    var textNode = root!.Nodes().FirstOrDefault(n => n is XText);\n\n                    if (textNode != null) {\n                        value = ((XText)textNode).Value;\n                        prop.SetValue(x, value, null);\n                    }\n","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/restsharp/RestSharp/blob/6a5082169257438cd085f822f050d93256a8e499/src/RestSharp.Serializers.Xml/XmlDeserializer.cs#L105-L141","documentation":"Thrown by the XML deserializer when two or more properties on the target class are decorated with [DeserializeAs(Content = true)]. Content=true marks a property as the element's inner text content; XML allows only one text node per element, so two such annotations are ambiguous and rejected.","triggerScenarios":"A class used as an XML deserialization target has two properties each annotated with [DeserializeAs(Content = true)]. Triggered during ExecuteAsync<T> with the XML deserializer when mapping the root element to the type.","commonSituations":"Copy-paste of an attribute across properties; misunderstanding of what Content=true means (intending 'include this in serialization'); refactoring that moved the attribute without removing the old one.","solutions":["Inspect the target class and remove [DeserializeAs(Content = true)] from all but one property.","Decide which single property represents the element's text content and keep only that attribute.","Use a unit test asserting at most one Content=true property per class to prevent regression."],"exampleFix":"// before\n[DeserializeAs(Content = true)] public string Value { get; set; }\n[DeserializeAs(Content = true)] public string Extra { get; set; }\n\n// after\n[DeserializeAs(Content = true)] public string Value { get; set; }\npublic string Extra { get; set; }","handlingStrategy":"validation","validationCode":"var contentProps = typeof(T).GetProperties().Select(p => p.GetCustomAttributes(typeof(DeserializeAsAttribute), false).Cast<DeserializeAsAttribute>().FirstOrDefault(a => a?.Content == true)).Count(a => a != null);\nif (contentProps > 1) throw new InvalidOperationException(\"Multiple [DeserializeAs(Content=true)] properties detected\");","typeGuard":null,"tryCatchPattern":"try { var result = client.GetAsync<T>(req); } catch (ArgumentException ex) when (ex.Message.Contains(\"two properties marked with SerializeAs(Content = true)\")) { /* fix the DTO, only one Content property allowed */ }","preventionTips":["Keep exactly one [DeserializeAs(Content = true)] per XML DTO.","Add a unit test asserting at most one Content attribute per DTO class."],"tags":["xml","deserialization","attribute","content-mapping"],"backgroundTag":null,"analyzedSha":"6a5082169257438cd085f822f050d93256a8e499","analyzedAt":"2026-08-13T20:38:25.807Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}