An exception "A generic error occured in GDI+" when generating reports using ActiveReports

676 views Asked by At

I am getting an exception while generating reports using the Active reports tool using reflection . I am pasting the log i got and the code. Code

  Protected Function GetReportStream(ByVal ActiveReportObject As Object) As Byte()
            Try
                ActiveReportObject.GetType().GetMethod("Run", New System.Type()     {System.Type.GetType("System.Boolean")}).Invoke(ActiveReportObject, New Object() {False})
            Catch
            End Try
            '' Create a memory stream to save the report document in RDF format.
            Dim memStream As New System.IO.MemoryStream()
            Dim document As Object =     ActiveReportObject.GetType().GetProperty("Document").GetValue(ActiveReportObject, Nothing)
            document.GetType().GetMethod("Save", New System.Type() {System.Type.GetType("System.IO.Stream")}).Invoke(document, New Object() {memStream})
            ''Create a byte array buffer to read the memory stream.
            Dim outBytes As Byte() = memStream.GetBuffer()
            memStream.Flush()
            memStream.Close()
            Return outBytes
        End Function

Log

    enter code here

System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
System.Drawing.ImageConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType)
DataDynamics.ActiveReports.Document.RawImageResourceData.FromImage(Image image)
#ar.ResourceManager.#U.#sKg.#gIc()
#ar.ResourceManager.#opk(Object sender, #Iok e)
#ar.GenericCache`3.#fOe(TKey k, Boolean purging)
#ar.ResourceManager.#zg(#ib resource)
DataDynamics.ActiveReports.Document.Page.#Df(Int16 fileVersion, BinaryWriter recordWriter, Hashtable savedResources, List`1 ownedResourceIds, List`1 referencedResourceIds)
DataDynamics.ActiveReports.Document.Page.Save(BinaryWriter writer, Int16 fileVersion, Hashtable savedResources)
DataDynamics.ActiveReports.Document.PagesCollection.Save(BinaryWriter writer, Int16 fileVersion, SaveOptions options)
1

There are 1 answers

0
Rajnish  Sinha On

Dont flush/close the image stream in that method call. Use the report end event to flush and close. So take the memStream.Flush() and memStream.Close() calls out of there and move it to report end event or close it after the report is finished running.