A generic error occurred in GDI+

Posted by: edkwchan on 18 October 2019, 1:46 am EST

    • Post Options:
    • Link

    Posted 18 October 2019, 1:46 am 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.

  • Posted 18 October 2019, 2:46 am 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.

  • Posted 18 October 2019, 3:07 am 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.

  • Posted 22 October 2019, 10: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.

  • Posted 23 October 2019, 5:00 am 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.

  • Posted 15 July 2020, 2:07 am EST

    Hi

    The GDI+ error is still bothering me even though I have paid to upgrade to version 14. The error is observed on all reports which has Picture control with image fed from the code shown in the original question.

    I am sorry that the project is too big to produce a stripped down sample. Moreover it is intermittent and is hard to reproduce. Whenever it is shown, the only solution we get is to recycle the application pool (i.e. killing all sessions and restart the site) and it is very annoying.

    Please help

  • Posted 15 July 2020, 5:45 am EST

    Hello,

    Could you please check with the latest setup as there is issue fixed related to Picture control in AR14 Sp1 and share the result with us.

    http://cdn.grapecity.com/ActiveReports/AR14/Hotfixes/ActiveReports-v14.1.20320.msi

    Also, can you please share the RDF with us so that we can look into the issue at our end.

    You can use the following code to save the RDF:

    SectionReport1.Document.Save(“test1.rdf”)

    Hope it helps.

    Thanks,

    Mohit

  • Posted 27 July 2020, 11:45 pm EST

    Hi

    I’ve upgraded to V14.1.20320 but still experience the GDI+ error.

    The log shows

    28 Jul 2020 10:10:44 ERROR [EventLogging] Error in running report INVO_Print

    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.WriteImageAs(Image image, ImageFormat format, BinaryWriter writer)

    at GrapeCity.ActiveReports.Controls.Image.Save(BinaryWriter writer, Boolean writeMagic)

    at GrapeCity.ActiveReports.SectionReportModel.Picture.get_ImageData()

    at PopularERP.Report.InvoicePageBase.InvoicePageBase_ReportEnd(Object sender, EventArgs e)

    at GrapeCity.ActiveReports.SectionReport.RaiseReportEnd()

    at GrapeCity.ActiveReports.SectionReport.ProcessPage()

    at GrapeCity.ActiveReports.SectionReport.RunImpl(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.RaiseReportStart()

    at GrapeCity.ActiveReports.SectionReport.ProcessInit(Boolean bDelayedInit)

    at GrapeCity.ActiveReports.SectionReport.RunImpl(Boolean syncDocument)

    at PopularERP.Report.ActiveReportHelper.RunActiveReport(SectionReport activeReport, ReportSetting reportSetting, Object dataSource)

    The source files and the saved rdf file are attached. Please help.

    INVO_Print.zip

  • Posted 28 July 2020, 5:31 am EST

    Hello,

    I have tired at my end and unable to reproduce the issue at my end. Could you please try after giving the user Admin rights on the machine. This solution had worked for one of our customer. Could you please give a try.

    Thanks,

    Mohit

  • Posted 17 September 2020, 12:55 am EST

    I think you mean giving admin right to the app pool account. Has tried but no luck. GDI+ error still happens occasionally.

  • Posted 17 September 2020, 4:35 am EST

    Hello,

    I meant to try after giving the Administration right to the user from whom you are logged in the machine.

    Thanks,

    Mohit

  • Posted 17 September 2020, 11:03 am EST

    Hi Mohit

    My application is a web form application. The executable is run under the app pool account, not a Windows user.

    Regards

    Edwin

  • Posted 18 September 2020, 7:17 am EST

    Hello,

    I have escalated the issue to the development team(AR-25133) and will inform you once I get any information from them.

    Thanks,

    Mohit

  • Posted 22 September 2020, 12:40 pm EST

    Hello,

    As per developer team, according to the stack trace the exception happens before RDF file can be saved. Did you try the stress test in the development environment?

    Thanks,

    Mohit

Need extra support?

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

Learn More

Forum Channels