I work with the console application / WebJob, which uses the EPPlus library to work with Excel files (.xlsx). My application basically opens up a set of workbooks and combines them as one file.
The application runs fine locally, but not on Azure. According to StackTrace error occurs inside the EEPlus library when trying to save an image (I assume this was done to move images from one book to another).
Unhandled Exception: System.ApplicationException: A generic error occurred in GDI+. ---> System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(Stream stream, ImageFormat format) at OfficeOpenXml.Drawing.ExcelPicture..ctor(ExcelDrawings drawings, XmlNode node) at OfficeOpenXml.Drawing.ExcelDrawing.GetDrawing(ExcelDrawings drawings, XmlNode node) at OfficeOpenXml.Drawing.ExcelDrawings.AddDrawings() at OfficeOpenXml.Drawing.ExcelDrawings..ctor(ExcelPackage xlPackage, ExcelWorksheet sheet) at OfficeOpenXml.ExcelWorksheets.Add(String Name, ExcelWorksheet Copy)
The source code that calls the open ConvertTo call.
Part = drawings.Part.Package.GetPart(UriPic); FileInfo f = new FileInfo(UriPic.OriginalString); ContentType = GetContentType(f.Extension); _image = Image.FromStream(Part.GetStream()); ImageConverter ic=new ImageConverter(); var iby=(byte[])ic.ConvertTo(_image, typeof(byte[])); var ii = _drawings._package.LoadImage(iby, UriPic, Part); ImageHash = ii.Hash;
After reading a few questions on this subject, I tried to change it using manual conversion and saving to a MemoryStream . However, I still get the error.
Part = drawings.Part.Package.GetPart(UriPic); FileInfo f = new FileInfo(UriPic.OriginalString); ContentType = GetContentType(f.Extension); _image = Image.FromStream(Part.GetStream()); byte[] iby; using (MemoryStream ms = new MemoryStream()) { _image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); iby = ms.ToArray(); } var ii = _drawings._package.LoadImage(iby, UriPic, Part); ImageHash = ii.Hash;
I really got stuck on what to try next. The exception does not cause much to happen, and I feel like I've tried all the suggestions there: checking the permissions on the folder and file (my application uses a temporary folder, which I think is safe), avoid reusing streams and soon .
Please let me know if you need more information and I will gladly express it.