.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]

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....