A generic error occurred in GDI+.
---
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at spr10695.0()
at Spire.Xls.Core.Spreadsheet.XlsWorkbookShapeData.AddPicture(Image image, ImageFormatType imageFormat, String strPictureName)
at spr4322.0(Image A_0, String A_1, ImageFormatType A_2)
at Spire.Xls.Core.Spreadsheet.Collections.XlsPicturesCollection.Add(Int32 topRow, Int32 leftColumn, Image image, ImageFormatType imageFormat)
at Spire.Xls.Collections.PicturesCollection.Add(Int32 topRow, Int32 leftColumn, Image image)
at ccms.Dogberry.Controllers.PrintController.ChecklistToExcel(ChecklistToExcelViewModel model) in C:\Projects\CCMS\CCMS\branches\checklistExport\ccms\ccms.Dogberry\Controllers\PrintController.cs:line 135
So far I have increased the permissions of the .net user in IIS, I've also tried to add Image.Dispose() calls to my code, but when I do, I get this error locally. Here is a snippet of my code:
- Code: Select all
foreach (var artwork in artworks)
{
Image thumb;
double width, height;
sheet.Range[letter + row].Text = " ";
if (!string.IsNullOrWhiteSpace(artwork.ThumbnailUrl))
{
WebClient wc = new WebClient();
byte[] bytes = wc.DownloadData(artwork.ThumbnailUrl);
MemoryStream ms = new MemoryStream(bytes);
thumb = Image.FromStream(ms);
width = thumb.Size.Width / 20.0;
height = thumb.Size.Height / 4.0;
sheet.Pictures.Add(row, columnCount + 1, thumb);
Again this code compiles and runs locally, but I error trying to create the XLS workbook on the last line in the code block provided (which is line 135 from the error). The error happens in my test environment, I have not tried to put this code in production yet.