Out Of memory exception Aspose Email

Get the following Exception when saving messages with large attachments (4 simultaneous threads a few 100MB attachments) to PST.

System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at ?.?.Write(Byte[] , Int32 , Int32 )
at ?.?.??(Stream , Stream )
at .??.??(Stream , HeaderCollection )
at .??.?(Byte[] )
at .??.?(Byte[] )
at .??.?()
at Aspose.Email.Mail.MailMessage.??(Stream , MailMessageLoadOptions )
at Aspose.Email.Mail.MailMessage.Load(Stream stream)

Hi Babu,

Thank you for sharing your concern with us.

Could you please share with us which version of Aspose.Email for .NET you are using at your end? I have tested this scenario using the latest version of Aspose.Email for .NET 4.1.0 and a test message with 100+ MB attachment, but couldn’t face any such exception as you have mentioned. Could you please give it a try using this latest version and let us know your feedback? If the issue still persists, please share with us a sample console application that we can use at our end for investigating this issue further. We’ll look into it and assist you accordingly.


Hi,

I’m experiencing the same issue. I have a mail with an attached PDF file. The size of the PDF file is 42 MB and it is consisting mostly of images.

I fetch the mail from the Exchange server and then, through the ExchangeWebServiceClient, saving it to a memory stream. I get the OOM exception on SaveMessage every time.

ExchangeWebServiceClient client = new ExchangeWebServiceClient(ConnectionString, UserName, Password, Domain);
...
MailMessage message = client.FetchMessage(uniqueUri);
using (MemoryStream ms = new MemoryStream())
{
    client.SaveMessage(uniqueUri, ms);
}

Exception:

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

at System.IO.MemoryStream.set_Capacity(Int32 value)

at System.IO.MemoryStream.EnsureCapacity(Int32 value)

at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)

at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)

at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count)

at System.IO.TextWriter.WriteLine(String value)

at Aspose.Email.Exchange.Schema.ExchangeWebServiceSoapExtension.RemoveInvalidCharacters(Stream from, Stream to)

at Aspose.Email.Exchange.Schema.ExchangeWebServiceSoapExtension.WriteInput()

at Aspose.Email.Exchange.Schema.ExchangeWebServiceSoapExtension.ProcessMessage(SoapMessage message)

at System.Web.Services.Protocols.SoapMessage.RunExtensions(SoapExtension[] extensions, Boolean throwOnException)

at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)

at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

at Aspose.Email.Exchange.Schema.ExchangeServiceBinding.GetItem(GetItemType GetItem1)

at Aspose.Email.Exchange.ExchangeWebServiceClient.SaveMessage(String messageUri, Stream stream)

/Andreas

Hi Andreas,


Thank you for writing to Aspose support.

Could you please share the sample message file with us that gives rise to this issue while downloading it? I have already tested this issue by downloading a sample message with 100MB of attachment file but couldn’t reproduce it at my end. May be your sample file will help us in this regard. We appreciate your cooperation in this regard.

For some reason I could not upload the pdf file to this post, but you can download it here:

[https://onedrive.live.com/redir?resid=407BC162447A855D!3882&authkey=!ADQF1OvCDohHUiU&ithint=file%2C.pdf ](https://onedrive.live.com/redir?resid=407BC162447A855D!3882&authkey=!ADQF1OvCDohHUiU&ithint=file%2c.pdf)

This file causes the OOM exception for me every time. By the way, I should mention that I use Aspose.Email 4.2.0.0.

/Andreas

Hi Andreas,


Thank you for providing the sample file.

I have tested the sample file with Exchange Server 2010 and the file was downloaded fine at my end. I am using the latest version of Aspose.Email for .NET 4.2.0 at my end on a 64-bit Windows 7 Operating system.

I would further like to share that we investigated one such issue in the past (NETWORKNET-34182) and the exception did arise on a 32-bit operating system. The error actually arises in the .NET framework that can’t be fixed by us as the same web service is used by our components. Please feel free to write to us in case you have any additional query in this regard.