私は電子メールクラスを持っています
public class EmailInfo
{
public MailAddress SenderEmailAddress { get; set; }
public MailAddressCollection ReceiverEmailAddress { get; set; }
public MailAddressCollection CCEmailAddress { get; set; }
public MailAddressCollection BCCEmailAddress { get; set; }
public AttachmentCollection Attachment { get; set; }
public string Subject { get; set; }
public DateTime EmailDate { get; set; }
}
およびタイプ EmailInfo のリストをシリアル化しようとすると。次のエラーが表示されます
Type 'System.Collections.Generic.List`1[[Darena.EmailParser.EmailInfo, Darena.EmailParser, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' with data contract name 'ArrayOfEmailInfo:http://schemas.datacontract.org/2004/07/Darena.EmailParser' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
を使用してシリアライズしています
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(EmailInfo));
MemoryStream ms = new MemoryStream();
ser.WriteObject(ms, emailInfos);
string jsonString = Encoding.UTF8.GetString(ms.ToArray());
ms.Close();
return jsonString;
どんな助けでも