When serializing a class I get an error if the XmlIgnore attribute is commented. When I uncomment the XmlIgnore attribute it works fine. Can anyone tell me why a property can't be serializable?
Normally, it will tell you why very clearly in the exception - look in particular at the InnerException; however, to summarise:
For a custom type SomeType
to be serializable via XmlSerializer
(either as the root object or via a property, ie public SomeType MemberName {get;set;}
)
public
object
is a no-go, for example; subtypes of SomeType
must be advertised in advance, typically via [XmlInclude(...)]
) abstract
), or have concrete implementations defined via [XmlInclude(...)]
Using [XmlIgnore]
removes the type from consideration, so types that are not xml-friendly can be avoided. You can also try IXmlSerializable
for those cases
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.