Free Support Forum - aspose.com

Attachment "ATT00001.txt" after serialize and deserialize Aspose MailMessage

Hi
When we serialize and deserialize Aspose MailMessage, attachment “ATT00001.txt” gets attached to deserialized object. Sample code is given below.
Can you please suggest how resolve this issue so that this attached will not get attached?
“Aspose.Email.dll” details are as below:-
File description:- Aspose.Email for .net 4.0
File Version: 4.1.0.0
product version: 2.14.04.29
(This is licenced dll)

    private void button1_Click(object sender, EventArgs e)
    {
        Aspose.Email.Mail.MailMessage msg = new Aspose.Email.Mail.MailMessage();
        msg.To = "--@--.com";
        msg.From = "--@--.com";
        msg.Subject = "test subject at ---" + DateTime.Now.ToLongDateString();
        msg.Body = " test body";
        SendEmailApi(msg);
    }
	
	public static void SendEmailApi(Aspose.Email.Mail.MailMessage msg)
    {
        byte[] bytes = ObjectToByteArray(msg);
        string mailMessage = Convert.ToBase64String(bytes);
        object objMsg = (Aspose.Email.Mail.MailMessage)ByteArrayToObject(bytes);
		//:
		//:
    }
	
	private static Object ByteArrayToObject(byte[] arrBytes)
    {
        MemoryStream memStream = new MemoryStream();
        BinaryFormatter binForm = new BinaryFormatter();
        memStream.Write(arrBytes, 0, arrBytes.Length);
        memStream.Seek(0, SeekOrigin.Begin);
        Object obj = (Object)binForm.Deserialize(memStream);
        return obj;
    }
	private static byte[] ObjectToByteArray(Object obj)
    {
        if (obj == null)
            return null;
        BinaryFormatter bf = new BinaryFormatter();
        MemoryStream ms = new MemoryStream();
        bf.Serialize(ms, obj);
        return ms.ToArray();
    }

Thanks,

@sharang,

Thank you for writing to Aspose support team.

I have tried this sample code using latest version Aspose.Email for .NET 18.5.0 but could not observe this issue. After deserialize operation, no extra attachment is observed. Could you please give it a try using latest version and share the feedback?