The first line fails with System.OutOfMemoryException
with the call Image.FromStream
:
using (System.Drawing.Image i = System.Drawing.Image.FromStream(new System.IO.MemoryStream(ucDocument1.UploadedFiles[0].FileBytes))) {
//additional code here
}
The byte array is coming from DevExpress.Web.ASPxUploadControl.ASPxUploadControl
object and a test which wrote the the fail cases byte arrays to the database and reread successfully from the database proves the byte arrays are valid. The operation is successful for PNG and JPG files of various sizes, and fails for particular known non-corrupt PNG/JPG files, even those that are smaller in size than the success cases. The files failing repeatedly give System.OutOfMemoryException
exception. How can this be resolved?