WCF serializing error - 'System.Net.Mail.MailAddress' cannot be serialized
-
18-09-2020 - |
Question
Please help me with this WCF error....How do I handle these builtin classes for WCF?
Type 'System.Net.Mail.MailAddress' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.
Solution
You could implement a surrogate that knows how to de(serialize) the MailAddress
type.
OTHER TIPS
Create a custom class which contains all the data / properties that you need from MailAddress
to transport across the wire and then map the MailAddress
to this custom class. You'll need to do the opposite on the client. If you keep the same property names / class hierarchy, a tool like AutoMapper
could reduce coding in the to / from mapping.