Hi,
A while back it seems a change in the Aspose.Network results in the mail objects disposing streams passed into it. For example:
AttachmentBase.SaveRawContent(Stream x)
closes the passed in stream. This means that code like the following:
public byte[] Content
{
get
{
using (MemoryStream stream = new MemoryStream())
{
attachment.SaveRawContent(stream);
return stream.ToArray();
}
}
}
Doesnt work any longer and throws an ObjectDisposedException. This to me is counter-intuitive as the ownership of the said stream is not within Aspose.
How can the code above be achieved with the newer versions of the library ?
rgds,
Laku.
Hi Laku,
Thanks for considering Aspose.
Which version of Aspose.Network are you using? The following code works fine with v4.8.1.
public class NetworkUtil
{
// private mail message member
private MailMessage msg;
///
/// default constructor
///
public NetworkUtil()
{
// initialize mail message by loading file with attachment
msg = MailMessage.Load(@“E:\Data\Aspose\temp\attachcase.eml”, MessageFormat.Eml);
}
public byte[] Content
{
get
{
using (MemoryStream stream = new MemoryStream())
{
msg.Attachments[0].SaveRawContent(stream);
return stream.ToArray();
}
}
}
}
If I get the public property Content by creating an instance of NetworkUtil class, it does not throw this exception.