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;
}
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;
}