cancel
Showing results for 
Search instead for 
Did you mean: 

ExportToStream method no longer returns System.IO.MemoryStream in CR 2008 SP5

Former Member
0 Kudos

We updated our Crystal 2008 Runtime from SP3 to SP5 (in attempt to fix the intermittent "invalid printer specified" error).  The application is a web service running in IIS.  This application has existed in this form for 9 years (started with crystal 8, then 10, then 11.5 r2 then 2008 sp3, now 2008 sp5).  It is currently used in 20+ production environments with different platforms (32 & 64 bit), different versions of Windows, Crystal, etc.  The same code has always worked fine in all of those instances.  As soon as we moved from SP3 to SP5, whenever we make the call to

Dim stream as System.IO.MemoryStream = myReportDocument.ExportToStream(ExportFormatType.PortableDocFormat)

we get the exception:  "Unable to cast object of type 'FileStreamDeleteOnClose' to type 'System.IO.MemoryStream'."

I verified the type of object now being returned by the ExportToStream method, and it is in fact of type FileStreamDeleteOnClose. Why all of a sudden does the ExportToStream method no longer return a memory stream??  Is anyone else experiencing this issue with Crystal 2008 SP5 (or SP4)?  Anyone found a solution?

Notes:

1. We can reproduce this error on our development machine (32 bit Windows Server 2003 SP2 / IIS 5 / .Net 2.0) and on the production machine (64 bit Windows Server 2008 SP2 / IIS 6 / .Net 3.0)

2. When I upgraded the service to VS2010 and ran the service in .Net 4.0, I still see the same problem (ExportToStream method does not return a memory stream), but the type of object returned in thise case is actually of type:  CrystalDecisions.ReportSource.EromReportSourceBase.%

3. Our web service runs in a separate app pool with administrator privileges.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I would like to say that we are seeing the exact same issue. Problems casting directly to an IO.MemoryStream. We have also noticed that it only occurs in certain environments, most likely linked to the Crystal SP Versions.

This sounds like a bug to me. Are these forums moderated? Or can we petition for a case?

Dim oStream As New System.IO.MemoryStream

    If Me.Report Is Nothing Then

    ElseIf aobjExportFormatType = ExportFormatType.NoFormat Then

      oStream = CType(Me.Report.ExportToStream(ExportFormatType.PortableDocFormat), IO.MemoryStream)

    Else

      oStream = CType(Me.Report.ExportToStream(aobjExportFormatType), IO.MemoryStream)

    End If

Greg

former_member183750
Active Contributor
0 Kudos

Hello Greg

The forums are moderated, however these are community forums, not technical support. E.g.; if there is time we will test and issue and if need be ask R&D for a fix. However, phone support gets much higher priority than queries posted here. For more details see the blog What are these 'support' forums good for anyhow?

At this time, I don't think I can look at the issue until next week or later. If this is a critical issue, please do create a phone case here:

http://store.businessobjects.com/store/bobjamer/en_US/pd/productID.98078100

Please note that if this does turn out to be a bug, your case will be refunded.

- Ludek

SCN Moderator

former_member183750
Active Contributor
0 Kudos

Using "SAP Crystal Reports, developer version for Microsoft Visual Studio", SP 5,  I created a new app from scratch. Used Don's code as well as KBA 1198587 - How to export a report to stream in C Sharp (C#) for Visual Studio .NET as a base and the report I used exported with no errors.

If you take the code as described by Don and create a new test app, do you still get the same issue?

- Ludek

Former Member
0 Kudos

Hi, I am having this same issue, though it seems that the pdf code works fine in sp3 with the stream (but haven't tested with sp5 yet), but what do I do about calling a word document, that doesn't work with the same code, could you help with it. It works with Memorystream in sp3, but it doesn't work with the stream in sp3, so I know it won't work in sp5. The memorystream of course doesn't work either in sp5.

Could you please point me to some code snipets that will fix this issue for word documents as well.

Thanks,

Brad

former_member183750
Active Contributor
0 Kudos

I will try to look at this in the next few days. But please do remember, these are community forums, not support. As such, phone support takes precedence. If this is an important issue, you may want to consider creating a phone incident here:

http://store.businessobjects.com/store/bobjamer/en_US/pd/productID.98078100

If the issue is confirmed as a bug, the incident will be refunded.

- Ludek

0 Kudos

Hi All,

This is by design, we never fully supported export to MemoryStream. See these 2 KBA's for more info:

2094425 - ExportToStream cause a GPF while exporting to System.IO.MemoryStream

2105311 - ExportToStream throws exception in SP 12 in Crystal Reports for Visual Studio

Only option is to not use MemoryStream, this will not be changed.

Don

Answers (3)

Answers (3)

0 Kudos

Hi,

In c# with ASP.net this is the code in my case fix this problem:

//Direct to Stream
//repDoc is ReportDocument
System.IO.Stream s = repDoc.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
//Convert Stream to Byte
byte[] b = new byte[s.Length];
int numBytesToRead = (int)s.Length;
rptStream.Read(b, 0  , numBytesToRead);
//Export PDF in Browser
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "applicattion/octect-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=Report.pdf");
Response.AddHeader("Content-Length", s.Length.ToString());
Response.BinaryWrite(((System.IO.MemoryStream)s).ToArray());
Response.End();
lenastodal
Product and Topic Expert
Product and Topic Expert
0 Kudos

The question is already very old and you tried to reach out to inactive members which means that your comment/the question in your comment won't be addressed. Please don't add comments to inactive threads but instead ask your own new question here: https://answers.sap.com/questions/ask.html

You should also check out our tutorial to learn more about asking and answering questions in the community: https://developers.sap.com/tutorials/community-qa.html

Many thanks!

Former Member
0 Kudos

Upon further research I can confirm that the problem arose subsequent to CR2008-SP3. SP3 works correctly.

The error:

"Unable to cast object of type 'FileStreamDeleteOnClose' to type 'System.IO.MemoryStream'."

when calling myReportDocument.ExportToStream(ExportFormatType.PortableDocFormat) only occurs on systems running SP4 and SP5.  SP3 behaves as correctly.

0 Kudos

Hi Guys,

Just tried this code and it works for me:

protected void Page_Load(object sender, EventArgs e)
{
    CrystalDecisions.CrystalReports.Engine.Database crDatabase;
    CrystalDecisions.CrystalReports.Engine.Tables crTables;
    CrystalDecisions.Shared.TableLogOnInfo crTableLogOnInfo = new CrystalDecisions.Shared.TableLogOnInfo();
    CrystalDecisions.Shared.ConnectionInfo crConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();

    CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new ReportDocument();
    //rpt.Load("C:\\Reports\\trustedauthentication1.rpt");
    rpt.Load("C:\\Reports\\formulas.rpt");

    System.IO.Stream oStream = null;
    byte[] byteArray = null;
    oStream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    byteArray = new byte[oStream.Length];
    oStream.Read(byteArray, 0, Convert.ToInt32(oStream.Length - 1));
    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(byteArray);
    Response.Flush();
    Response.Close();
    rpt.Close();
    rpt.Dispose();

    //CrystalReportViewer1.ReportSource = rpt;
}

Can you test also?

And use a tool like Fiddler to see it it is capturing any more details.

From what I see it seem's to be a timing issue, you are trying to close the temp files before the system or IIS is done with them. Could be something that was resolved in our code above SP 3.

You need to do more debugging to see who or why that function is generating the error.

Don

Former Member
0 Kudos

Hello Don,

In my case we're not sending the resulting byte array to a browser, but saving the resulting byte array to a database.

Further testing indicates CRW fails when the object is a memorystream, but works with a plain stream.

This snippet fails (using a memorystream):

Dim memstream As System.IO.MemoryStream = Nothing

Try

    memstream = objRep.ExportToStream (CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)

Catch ex As Exception

    EventLogging.EventPost(ex)

End Try

This will throw the following exception:

"Unable to cast object of type 'FileStreamDeleteOnClose' to type 'System.IO.MemoryStream'."

Works fine in CRW 2008 SP3 and prior.  Broken in SP4 and SP5 from what I have determined.

This snippet works using system.io.stream instead of memorystream:

               

Dim ostream As System.IO.Stream = Nothing

Try

ostream = objRep.ExportToStream(CrystalDecisions.Shared.

ExportFormatType.PortableDocFormat)

Catch ex As Exception

    EventLogging.EventPost(ex)

End Try

Definitely something has changed in SP4/SP5.  A memory stream worked for many years...

Please try using a memorystream in your test code and see what happens.

former_member183750
Active Contributor
0 Kudos

Hello steve

I wonder if this KBA will help:

1523063 - ExportToHttpResponse throws exception - A first chance exception of type 'System.Threading...

I know it's not exactly the same error you are seeing, but looking at the link to MS referenced in the KBA makes me wonder...

- Ludek

Follow us on Twitter

Got Enhancement ideas? Try the SAP Idea Place

Share Your Knowledge in SCN Topic Spaces

Former Member
0 Kudos

This error has suddenly occurred on our production server as well.

Our code has been running prior to this, unaltered for over 4 years.

I don't have an answer, but clearly something has occurred.  I believe we are running the CR2008 SP4 runtimes.