A generic error occurred in GDI+

Posted by: edkwchan on 17 October 2019, 4:46 pm EST

  • Posted 17 October 2019, 4:46 pm EST

    Recently we have intermittent errors when printing images in AR.
    The exception is

    System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
    at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
    at GrapeCity.ActiveReports.Controls.Image.#Yzd()
    at GrapeCity.ActiveReports.SectionReportModel.Picture.#7UC(Image image1, Image image2)
    at GrapeCity.ActiveReports.SectionReportModel.Picture.QuickSave(BinaryWriter binWriter)
    at GrapeCity.ActiveReports.SectionReportModel.Section.#jBb(Stream stream)
    at GrapeCity.ActiveReports.SectionReportModel.Section.#gBb()
    at #sxA.#vqb.#FEb(Boolean bTemp, #pqb pItem, #rqb pRegion)
    at #sxA.#mqb.#SDb(Section section, Int32 insPos)
    at #sxA.#vqb.#DEb(Boolean bAllowGrowth)
    at #sxA.#vqb.#vEb()
    at #sxA.#vqb.#bZA(Page newPage, Single left, Single top, Single right, Single bottom, UInt32 flags, UInt32& status)
    at GrapeCity.ActiveReports.SectionReport.#4yb()
    at GrapeCity.ActiveReports.SectionReport.Run(Boolean syncDocument)
    at PopularERP.Report.InvoicePrintBase.ProcessPages(InvoicePageBase originalPageReport, String originalPageTitle, String originalWatermark, InvoicePageBase accountsCopyPageReport, String accountsCopyPageTitle, String accountsCopyWatermark, InvoicePageBase DNPageReport, String DNPageTitle, String DNWatermark, Boolean skipAccountsCopy, Boolean skipDN)
    at PopularERP.Report.Sales.INVO_Print.INVO_Print_ReportStart(Object sender, EventArgs e)
    at System.EventHandler.Invoke(Object sender, EventArgs e)
    at GrapeCity.ActiveReports.SectionReport.#hzb()
    at GrapeCity.ActiveReports.SectionReport.#1yb(Boolean bDelayedInit)
    at GrapeCity.ActiveReports.SectionReport.Run(Boolean syncDocument)

    The code that I believe causing the error


    Picture logoPic = new Picture();
    logoPic.Image = Image.FromStream(memoryStream);
    logoPic.Width = SectionReport.CmToInch(18);
    logoPic.Height = SectionReport.CmToInch(2.94F);
    logoPic.PictureAlignment = PictureAlignment.TopLeft;
    logoPic.SizeMode = SizeModes.Clip;
    pageHeader.Controls.Add(logoPic);


    The exception is thrown recently in production server from time to time. We cannot repeat it in development server. We have no changes in code recently. Please help.
  • Replied 17 October 2019, 5:46 pm EST

    If it matters, our application is a ASP.NET webform application using .NET Framework 4.5.2. ActiveReport is 11.3. Production server is running in Azure VM.
  • Replied 17 October 2019, 6:07 pm EST

    Hello,

    When you are loading an image from a Stream, you have to keep the stream open for the lifetime of the image. The exception might be caused because the memory stream gets closed even before the image gets disposed.
    Thus, please try using the below mentioned code snippet at your end:

    using (var memoryStream = new MemoryStream("Your image data"))
    {
    using (img = Image.FromStream(memoryStream ))
    {
    Picture logoPic = new Picture();
    logoPic.Image = img;
    logoPic.Width = SectionReport.CmToInch(18);
    logoPic.Height = SectionReport.CmToInch(2.94F);
    logoPic.PictureAlignment = PictureAlignment.TopLeft;
    logoPic.SizeMode = SizeModes.Clip;
    pageHeader.Controls.Add(logoPic);
    }
    }


    This should help you resolve the issue.

    >>when printing images in AR
    From the above statement, I assume that you are exporting the report to PDF. If this is the case and the above code does not help, set the ConvertMetaToPng property of PdfExportOptions to True.

    Regards,
    Esha
    Note: AR11 support is discontinued now, as it is not in the maintenance mode. Refer the "Technical Support" tab here: https://www.grapecity.com/controls/activereports/version-history.
  • Replied 22 October 2019, 1:15 pm EST

    The error occurred when exporting to Excel and Word too, not just limited to PDF.
    Anyway I have tried setting ConvertMetaToPng to true but it is not helping.

    I have also tried using ImageConverter to replace all codes using MemoryStream. So my code is not using MemoryStream now and so it should not be related to closing the stream too soon. From the stack,

    System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
    at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
    at GrapeCity.ActiveReports.Controls.Image.#Yzd()

    it is clear that System.Drawing.Image.Save is invoked from the Image control inside the report.
  • Replied 22 October 2019, 8:00 pm EST

    Hello,

    Thank you for the details so far. Is the issue observed with all the reports at your end, or with a specific report?
    I would request you to share a stripped down sample showing the issue. This will help us observe the same and assist you in the right direction. In case you wish to share it over a private platform, you can create a case on SupportOne with the same credentials as from this website: https://supportone.componentone.com

    Thanks.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels