This is a migrated thread and some comments may be shown as answers.

System.OutOfMemoryException: Out of memory

8 Answers 1117 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Glenn
Top achievements
Rank 1
Glenn asked on 27 Mar 2014, 05:55 PM
 System.OutOfMemoryException: Out of memory.
   at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
   at Telerik.ReportViewer.WinForms.DrawablePage.Draw(Graphics graphics, Rectangle rectangle) in c:\temp\reporting\@RBuild-2334\Reporting_Build\Source\Code\Telerik.ReportViewer.WinForms\DrawablePage.cs:line 47
   at Telerik.ReportViewer.WinForms.InteractivePageLayout.LayoutItem.DrawContent(Graphics graphics) in c:\temp\reporting\@RBuild-2334\Reporting_Build\Source\Code\Telerik.ReportViewer.WinForms\InteractivePageLayout.cs:line 334
   at Telerik.ReportViewer.WinForms.InteractivePageLayout.DrawPages(Graphics graphics, Rectangle rectangle, Int32 pageNo) in c:\temp\reporting\@RBuild-2334\Reporting_Build\Source\Code\Telerik.ReportViewer.WinForms\InteractivePageLayout.cs:line 98
   at Telerik.ReportViewer.WinForms.WinViewer.OnPaint(PaintEventArgs eventArgs) in c:\temp\reporting\@RBuild-2334\Reporting_Build\Source\Code\Telerik.ReportViewer.WinForms\WinViewer.cs:line 869
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Now previously in our 2012 we were getting something similar to this when a control with the embedded control was displaying a report built inside Visual Studio.  We upgraded to Q3 2013's release, removed the older reports, added a class that builds the XML version (trdx files) and the error went away.  Now a different Out of Memory exception error (listed above) recently started occurring.  Originally the image we used was streamed from the database (for logos) but now they are local to the application (I cannot point to the post, but on your ASP forums, someone suggested doing that with other Telerik controls that used images).  Our app is a desktop app (non-wpf) that uses Telerik Reporting.  The above error only seems to occur in certain situations, so not every time.  it occurs on reports that vary in pages (1-75).  Our reports that go into the reportbook do not have this problem (avg 136 reports totaling ~900 pages).  We have 2 report viewers (2 separate user controls on same form) that display the reports.  One displays a single report while the other display the report book when all the single reports are loaded.

In 2012 release we were getting (using code behind version) about 80% of the clients were getting this error:
​ System.OutOfMemoryException: Out of memory.
   at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
   at System.Drawing.Image.FromStream(Stream stream)
   at Telerik.ReportViewer.WinForms.DrawablePage.Draw(Graphics graphics, Rectangle rectangle)
   at Telerik.ReportViewer.WinForms.InteractivePageLayout.LayoutItem.DrawContent(Graphics graphics)
   at Telerik.ReportViewer.WinForms.InteractivePageLayout.DrawPages(Graphics graphics, Rectangle rectangle, Int32 pageNo)
   at Telerik.ReportViewer.WinForms.WinViewer.OnPaint(PaintEventArgs eventArgs)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.UserControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Now this could just be me, but I'm starting to think it's not the loading of our logo onto the report, but drawing the report itself since the logo is no longer read from the database but read from file.  In my case, we discovered that working with trdx files are easier to create a dynamic tables than the code behind version.

Here is a sample of how the report is built.

/// <summary>
/// Returns a Telerik Report for use in the Telerik ReportViewer
/// </summary>
/// <param name="reportInfo"> of the report to generate, see ReportInfo class</param>
/// <returns></returns>
public Telerik.Reporting.Report GetReport(ReportInfo reportInfo)
{
#region hallway monitors
if (reportInfo == null)
throw new NullReferenceException("ReportInfo is missing or null.");

if (reportInfo.Name == null)
throw new NullReferenceException("Report Name is missing or null.");

#endregion

XDocument doc = CreateXDocument(reportInfo); //the trdx file

// open the report
BufferedStream stream = new BufferedStream(new MemoryStream());
stream.Write(Encoding.ASCII.GetBytes(doc.ToString()), 0, doc.ToString().Length);
stream.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(stream);

System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
settings.IgnoreWhitespace = true;

XmlDocument xmlDoc = GetXmlDocument(doc);
Telerik.Reporting.Report report;

using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(sr, settings))
{
Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
}

Telerik.Reporting.TextBox tbHeader = (Telerik.Reporting.TextBox)report.Items["pageHeaderSection1"].Items["textBoxHeader"];
tbHeader.Value = reportInfo.Title;

if (reportInfo.CompanyLogo != "" && reportInfo.CompanyLogo != null)
{
Telerik.Reporting.PictureBox pictureBoxCompanyLogo = (Telerik.Reporting.PictureBox)report.Items["pageHeaderSection1"].Items["pictureboxCompanyLogo"];
pictureBoxCompanyLogo.MimeType = reportInfo.CompanyLogoExt != "" ? "Image/" + reportInfo.CompanyLogoExt.ToUpper() : "";
pictureBoxCompanyLogo.Value = Image.FromFile(reportInfo.CompanyLogo);
}

foreach (TableInfo tableinfo in reportInfo.Tables)
{
Telerik.Reporting.Table table = (Telerik.Reporting.Table)report.Items["detailSection1"].Items[tableinfo.ReportTableName];
table.DataSource = tableinfo.DataSource;
}

return report;

}

​ private XmlDocument GetXmlDocument(XDocument document)
{
using (XmlReader xmlReader = document.CreateReader())
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlReader);
if (document.Declaration != null)
{
XmlDeclaration dec = xmlDoc.CreateXmlDeclaration(document.Declaration.Version,
document.Declaration.Encoding, document.Declaration.Standalone);
xmlDoc.InsertBefore(dec, xmlDoc.FirstChild);
}
return xmlDoc;
}
}

private XDocument CreateXDocument(ReportInfo reportInfo)
{
XDocument doc = new XDocument();

_isLandscape = reportInfo.Layout == ReportProperties.Layout.LANDSCAPE ? true : false;

doc.Add(new XElement(XML_NAME_SPACE + "Report"
, new XAttribute("Width", reportInfo.Layout.Width.ToString() + "in")
, new XAttribute("Name", reportInfo.Name)));

XElement rootItems = new XElement(XML_NAME_SPACE + "Items");
rootItems.Add(PageHeaderSection());
rootItems.Add(DetailSection(reportInfo));
rootItems.Add(PageFooterSection());

doc.Root.Add(rootItems);
doc.Root.Add(StyleSheets());
doc.Root.Add(PageSettings());

return doc;
}

8 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 01 Apr 2014, 03:18 PM
Hi Glenn,

The exception is most probably caused by an exceeding number of records rendered in the report definitions and the insufficient GDI+ resources to render them. Try reducing the displayed data to sets meaningful for the user, and in the background you can export a separate instance of the report without filtering its data.

In order to investigate further the issue, please open a support ticket and send us a runnable sample project with test data, where the issue is reproducible at your side. Include also details about the tested machine.

Regards,
Stef
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
samir
Top achievements
Rank 1
answered on 05 May 2017, 10:51 AM

Hello Stef,

Can you please be more specific, about why the error is thrown randomly on the website:

++++++++++++

Exception information: 
    Exception type: OutOfMemoryException 
    Exception message: Out of memory.
   at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
   at Telerik.Sitefinity.Modules.Libraries.Thumbnails.LazyThumbnailGenerator.SaveOrGenerateThumbnail(MediaContent liveMediaContent, String 

+++++++++++++++++++++++

 

Please guide us how to investigate the issue ahead..

Warm Regards,

0
Stef
Telerik team
answered on 05 May 2017, 11:43 AM
Hello Samir,

The stack trace does not contain information about Telerik Reporting.
It is a general error message pointing to a problem in the memory handling of the application. such issues can be related to:
  • Insufficient memory for the process and overload - too much data and resources are requested at a time and the server machine cannot handle them;
  • Custom code that creates streams which are not handled correctly. If you use streams to load images, check if they are created and disposed correctly. Image objects require streams to remain open until the Image object is used.
  • The machine lacks  access to required GDI+ methods, usually used by image rendering mechanisms. Such issues can be observed with Azure WebSites which are known to have limited access to the GDI+ API.


This discussion can give you more hints - Sitefinity Devs.
If you need further help, please submit a ticket to Telerik Sitefinity, which will be addressed by the team having the knowledge of the used product.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Kris Nobels
Top achievements
Rank 2
answered on 15 Mar 2021, 02:52 PM
Sitefinity Devs link is dead.  Redirect to google+ is no longer supported.
0
Neli
Telerik team
answered on 18 Mar 2021, 08:45 AM

Hello Kris,

Can you give us more details about the issues that you are experiencing? Maybe you can attach a Trace Listener and send us the generated log file.

I will be looking forward to receiving an update from you.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Kris Nobels
Top achievements
Rank 2
answered on 18 Mar 2021, 10:30 AM

I got internal ticket running @ telerik (ticket 1511123)

It's related to the print problems from Microsoft (update that crashes W10)

1 of the 2 updates was installed. (I did uninstall) but problem still exists. :-(

On my machine i can reproduce ...
You still need the trace listener ?

0
Neli
Telerik team
answered on 23 Mar 2021, 06:46 AM

Hello Kris,

I am sorry to hear that the problem is not resolved after uninstalling. I would recommend attaching the log from Trace Listener in support ticket #1511123. We will be looking forward to receiving an update from you.

Regards,
Neli
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
n/a
Top achievements
Rank 1
Iron
answered on 02 Jun 2021, 06:23 PM

I too getting out of memory issue in PROD env and recently, we able re-create same issue other environments as well but couldn't found the proper solution

Load test

concurrent 250 users with 360 seconds of ramp up time - Work fine

concurrent 500 users with 360 seconds of ramp up time - Exception (out of memory and GDI+ issue)

Here below is the exception we were getting out of memory issue

System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData):95
Telerik.Reporting.Processing.Imaging.ImageUtils.LoadImage(Stream stream)
Telerik.Reporting.Processing.Imaging.ImageUtils.CreateImage(Byte[] data):23
Telerik.Reporting.Writing.PictureContainerWriter.WriteContent(DocumentWriter writer, ReportItem element, ElementPageInfo pageInfo):110
Telerik.Reporting.Writing.ProcessingContentElementWriter`1.WriteElement(T element, ElementPageInfo pageInfo, DocumentWriter writer):19
Telerik.Reporting.Writing.ProcessingElementWriter`1.Write(T element, ElementPageInfo pageInfo, DocumentWriter writer):45
Telerik.Reporting.Writing.ElementWriter`1.Telerik.Reporting.Writing.IElementWriter.StartWrite(LayoutElement element, ElementPageInfo pageInfo, DocumentWriter writer):16
Telerik.Reporting.Writing.WriteStartOperationsDispatcher.Write(IElementWriter writer, LayoutElement element, ElementPageInfo pageInfo, DocumentWriter documentWriter)
Telerik.Reporting.Writing.WriteOperationsDispatcher.Visit(PictureBox pictureBox)
Telerik.Reporting.Processing.PictureBox.Accept(ProcessingElementVisitor visitor)
Telerik.Reporting.Processing.ProcessingElementVisitor.Visit(LayoutElement element)
Telerik.Reporting.Writing.DocumentWriter.Telerik.Reporting.BaseRendering.IWriter.WriteStartElement(LayoutElement element, ElementPageInfo pageInfo)
Telerik.Reporting.BaseRendering.PageHandler.Telerik.Reporting.Paging.IPageHandler.StartElement(LayoutElement element, ElementPageInfo info):13
Telerik.Reporting.Paging.PageStartElement.AddToPage(IPageHandler handler)
Telerik.Reporting.Paging.PageElementLayer.AddToPage(IPageHandler handler):14
Telerik.Reporting.Paging.PageElementManager.AddToPage(IPageHandler handler):12
Telerik.Reporting.Paging.PageCompositionBase.AddElementsToPage():7
Telerik.Reporting.Paging.PageCompositionBase.SendPhysicalPages():18
Telerik.Reporting.Paging.PageCompositionBase.OutputPage():410
Telerik.Reporting.Paging.PageCompositionBase.CreatePages():250
Telerik.Reporting.Paging.PagerBase.Telerik.Reporting.Paging.IPager.CreatePages(IPageHandler handler, LayoutElement root):37
Telerik.Reporting.BaseRendering.RenderingExtensionBase.Render(LayoutElement root, Hashtable renderingContext, Hashtable deviceInfo, CreateStream createStreamCallback, EvaluateHeaderFooterExpressions evalHeaderFooterCallback, PageSettings pageSettings):91
Telerik.Reporting.BaseRendering.RenderingExtensionBase.Render(Report report, Hashtable renderingContext, Hashtable deviceInfo, CreateStream createStreamCallback, EvaluateHeaderFooterExpressions evalHeaderFooterCallback)
Telerik.Reporting.Processing.ReportProcessor.RenderCore(ExtensionInfo extensionInfo, IList`1 processingReports, Hashtable deviceInfo, IRenderingContext renderingContext, CreateStream createStreamCallback):430
Telerik.Reporting.Processing.ReportProcessor.ProcessAndRender(String format, ReportSource reportSource, Hashtable deviceInfo, IRenderingContext renderingContext, CreateStream createStreamCallback):40
Telerik.Reporting.Processing.ReportProcessor.ProcessAndRenderStateless(String format, ReportSource reportSource, Hashtable deviceInfo, IRenderingContext renderingContext, CreateStream createStreamCallback)
Telerik.Reporting.Processing.ReportProcessor.RenderReport(String format, ReportSource reportSource, Hashtable deviceInfo):

 

Basically, we print PDF report using Telerik and we used the code which can programmatically generate PDF (Attach image of the code snippet).

Application host in Azure app service

Telerik version 13.2.19.1030

What we do in report,

 - PictureBox - print images which are get from blob server

 - Label & Textbox - Lots of dataset shows in PDF (Normal PDF pages are around 8-10 | maximum can be 20-50 pages)

Datasource - Bind dynamically where we get from stored procedure

 

Looking forward proper solution to mitigate this issue.

Thanks

Neli
Telerik team
commented on 08 Jun 2021, 03:28 PM

Firstly, I would recommend upgrading to the latest version. With each release, we try to improve the rendering. Also, can you test exporting without the image. 

Can you share Fiddler logs with us in order to see if there are any specific errors in the requests? To do this you will need to install the Fiddler Jam extension then generate a log and share it with us.

Tags
General Discussions
Asked by
Glenn
Top achievements
Rank 1
Answers by
Stef
Telerik team
samir
Top achievements
Rank 1
Kris Nobels
Top achievements
Rank 2
Neli
Telerik team
n/a
Top achievements
Rank 1
Iron
Share this question
or