GDI exception when rendering to HTML

2 posts, 0 answers
  1. Daniel
    Daniel avatar
    16 posts
    Member since:
    Oct 2007

    Posted 01 May 2012 Link to this post


    Hello,

    I run into the following .Net exception that seems to be triggered from the Telerik Reporting engine: "Unhandled exception, filepath [Telerik.ReportViewer.axd]System.InvalidOperationException: Invalid image data. ---> System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+." Maybe someone has seen this before? Looks a bit related to this problem.

    The problem seems specifically to occur when I render a textbox control that is rotated for 90 degrees, so with vertical text rendering. Also the problem only occurs during HTML rendering, for example PDF rendering is no problem. It seems that vertical text in html gets rendered as an image. The GDI+ exception occurs when this textbox is rendered. It also seems to be related to bigger data amounts, having reports with at least 50 pages.

    Googling for a solution it seems that this exception often occurs:

    1. Because of a rights issue when output is written to a file directory. This does not seem to be likely since I choose to render entirely in memory.
    2. The generated bitmap is not properly disposed. This would be something in the Telerik rendering engine and is out of my control.

      Some more background:

    In our app we do generate the report layout programmatically and I have not been able to reproduce this problem using a report generated with the report builder. I also logged a support ticket for this issue but the response was "please send a sample project." Unfortunately I was not able to reproduce the problem in a sample project. I'll keep you posted when I get a solution from Telerik though.

    Stack trace:

    [5232] 24-4-2012 12:10:02 [12:10:02] Unhandled exception, filepath [/Florin/Telerik.ReportViewer.axd]System.InvalidOperationException: Invalid image data. ---> System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
        at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
        at Telerik.Reporting.Processing.Imaging.ImageUtils.SaveBitmap(Stream stream, Image image)
        at Telerik.Reporting.Processing.Imaging.ImageUtils.ResolveImage(Image image)
        at Telerik.Reporting.Processing.Imaging.ImageUtils.GetImageData(Object value)
        --- End of inner exception stack trace ---
        at Telerik.Reporting.Processing.Imaging.ImageUtils.GetImageData(Object value)
        at Telerik.Reporting.Processing.Imaging.ImageContainer..ctor(Object value)
        at Telerik.Reporting.HtmlRendering2.Common.Writers.ImageWriter.SaveImageInStream(Image image)
        at Telerik.Reporting.HtmlRendering2.Common.Writers.RotatedTextElement.WriteImage(Image image, Single imageWidth, Single imageHeight, Single left, Single top)
        at Telerik.Reporting.HtmlRendering2.Common.Writers.RotatedTextElement.WriteElement(ProcessingElement element, RectangleF writeTextRectangle, RectangleF imageRectangle)
        at Telerik.Reporting.HtmlRendering2.Common.Writers.RotatedTextElement.End(ProcessingElement element, ElementPageInfo pageInfo)
        at Telerik.Reporting.Paging.PageElementLayer.AddToPage(IPageHandler handler)
        at Telerik.Reporting.Paging.PageElementManager.AddToPage(IPageHandler handler)
        at Telerik.Reporting.Paging.PageCompositionBase.SendPhysicalPages(Boolean lastPage)
        at Telerik.Reporting.Paging.InteractiveLayout.PageComposition.PageOverride()
        at Telerik.Reporting.BaseRendering.RenderingExtensionBase.Render(Report report, Hashtable renderingContext, Hashtable deviceInfo, CreateStream createStreamCallback, EvaluateHeaderFooterExpressions evalHeaderFooterCallback)
        at Telerik.Reporting.Processing.ReportProcessor.RenderCore(ExtensionInfo extensionInfo, IList`1 reports, Hashtable deviceInfo, Hashtable renderingContext, CreateStream createStreamCallback)
        at Telerik.ReportViewer.WebForms.ReportPageOperation.RenderReport(String format, IList`1 processingReports, Hashtable deviceInfo, Hashtable renderingContext)
        at Telerik.ReportViewer.WebForms.ReportRenderOperation.PerformOperationOverride()
        at Telerik.ReportViewer.WebForms.BasicHandler.ProcessRequest(HttpContext context)
        at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
        at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
  2. Daniel
    Daniel avatar
    16 posts
    Member since:
    Oct 2007

    Posted 08 May 2012 Link to this post

    For those who are interested, with the help of support we found the cause of the GDI+ exception and implemented a workaround.
    The problem occurred only in HTML rendering, with the following specific conditions:
    • Textbox had an angle of 90 degrees, so text is displayed vertically.
    • The group contains more than 1200 detail rows

    PDF and other rendering engines inserted a proper page break in the page in these cases, but the interactive view of the html rendering tried to render an image box that exceeded the size that could be handled. The image box was rendered for the entire rowspan. The provided workaround is to wrap the textbox in a panel. In this case only the textual part of the textbox is rendered as an image. Problem solved.

    Below the reply from Telerik support:
    ==
    "The exception is not in our code, it is in the GDI+ and the GDI+ is unmanaged code which is hard to handle. 

    The PDF has no problems because it supports text rotation natively and no image rendering occurs there. 

    The HTML on the other hand is a whole different story. Due to compatibility issues we have decided to render the rotated text as a bitmap. In your case, even if it wasn't a picture the browser wouldn't handle a simple <DIV> tag with such a Height as you can test yourself by removing the Angle and running the report. Also even if the GDI+ could handle image with these dimensions you would surely get Out Of Memory Exception at some point, so in either case such scenario would never work. 

    We cannot tell you when a fix for this issue will be provided because it depends entirely on the browsers evolution and our goal is things to be as consistent as possible. 

    Possible workarounds:
    1. Do not use rotated text.
    2. Replace the rotated TextBox with a Panel and then inside the Panel put the rotated TextBox. This way the textbox will be kept small and won't cause trouble. Note: This solution will not allow you to align the TextBox in the middle - it will be always top or bottom.
    3. Render the report as PDF and display it directly into the browser (without viewer). See Exporting a report to PDF programmatically for more information."
    ==
  3. DevCraft banner
Back to Top