1

使用 Active 报告工具使用反射生成报告时出现异常。我正在粘贴我得到的日志和代码。 代码

  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

日志

    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)
4

1 回答 1

0

不要在该方法调用中刷新/关闭图像流。使用报告结束事件刷新和关闭。因此,从那里取出 memStream.Flush() 和 memStream.Close() 调用并将其移动到报告结束事件或在报告完成运行后关闭它。

于 2014-12-03T18:43:55.943 回答