微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

.net – 如何序列化邮件?

当使用los foratter串连化一个mial消息时,我得到以下内容.

错误:Sys.WebForms.PageRequestManagerServerErrorException:错误序列化System.Net.Mail.MailMessage类型为“System.Net.Mail.MailMessage”的值.

有没有一个简单的方法来序列化这个对象,或者我要分别搜索每个ofhte属性

解决方法

可惜的是,System.Net.Mail.MailMessage类没有被标记为可序列化.所以,是的,你需要自己去做.以下博客文章中介绍的技术可以让您了解如何继续: How to Serialize a MailMessage …基本上,您将需要单独拉出每个属性.引用:

To serialize the properties of a MailMessage object you can create a
new class and create a property of MailMessage type for it that embeds
your MailMessage in the class. In this new class you can implement
IXmlSerializable interface to manually serialize its MailMessage. Here
I create this class and call it SerializableMailMessage […]

[code implementation of WriteXml() and readxml() methods follow; see source link]

原文地址:https://www.jb51.cc/aspnet/246249.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐