tags:

views:

261

answers:

1

Hello,

we have an asp.net 3.5 application that allows users to generate many charts and export them via pdf. This works fine for smaller pdfs (less than 100 pages), but when we do larger ones, we get random errors. some of the errors we have seen are:

--System.OutOfMemoryException
--Could not render the HTML string. Could not get image from html string. Try to set LoadHtmlConcurrencyLevel = 1..
--Clone error. Out of memory..
--Timeout waiting for conversion to finish.
--System.OutOfMemoryException: Out of memory. at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) at System.Drawing.Image.FromStream(Stream stream)

If I run the big report multiple times, i usually get different exceptions. Sometimes I can get IIS to crash and I have to do a iisreset to get the application back up.

Here is the code we run. We create the PDF document with the charts (png images) and then export it out to a byte array and put it in a memorystream. We pass the memory stream to a function that rotates some of the images, etc and then call the doc.save method to export it.

Dim mainPageBytes() As Byte = PDF.GetBytes
Dim stream As New System.IO.MemoryStream(mainPageBytes)
Dim existingDoc As New PDFCreator.Document(stream)
Dim doc As PDFCreator.Document = GetDocument(mainPageBytes,    GetChartingPageNumbers(PDF.ConversionSummary), pageOrientation, user, existingDoc)
doc.Save(response, True, Me.DocumentName)
+1  A: 

IIS has limits on the scripts that run on it, both for memory and runtime. Presumably your script is going over the runtime and/or memory limits. These can be set in the IIS configuration settings, but they're generally there for a reason (to prevent a single script from eating up all the memory on the server, or to prevent a script from running forever in an infinite loop which you would have no way of exiting short of restarting IIS.)

Turn on debugging (which disables those limits) and determine how much memory your scripts are actually using when they crash by outputing queryObj("PeakWorkingSetSize") to a log file.

WarrenB