on 01-13-2015 11:35 PM
Hi Team, I'm getting the below error. Can some one please assist me on this? I'm using Windows 2012 R2 server and CrystalReport Runtime 13.0.x version installed on the server. Application built on Any CPU using VisualStudio 2010 Error Message: HandlingInstanceID: c68a0e37-5eb5-4cb5-9587-6d6030b79b48 An exception of type 'System.InvalidCastException' occurred and was caught. --------------------------------------------------------------------------- 01/13/2015 16:26:11 Type : System.InvalidCastException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : Unable to cast object of type 'FileStreamDeleteOnClose' to type 'System.IO.MemoryStream'.
Hi Singareddy
Please provide the following information:
Service pack used with your SAP Crystal Reports, Developer Version for Visual Studio .NET
Code, or steps as to how to reproduce the issue
Is this happening on your development computer or after you deploy the app?
- Ludek
Senior Support Engineer AGS Product Support, Global Support Center Canada
Follow us on Twitter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It appears you are using System.IO.MemoryStream in your export method
Don't, not supported. Use System.IO.Stream.
See this KBA
SAP Note 2105311 - ExportToStream throws exception in SP 12 in Crystal Reports for Visual Studio
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have been reading a lot of posts about this issue. I have also ready the KBA at the link provided, but it does not exactly state the issue that I am having, but it is very close.
I too am receiving the error: Unable to cast object of type 'FileStreamDeleteOnClose' to type 'System.IO.MemoryStream'. However, that is due to code that I have been using for several years where I was turning the crystal reports returned IO.Stream and then casting it to an IO.MemoryStream.
The problem now is not that I am trying to get an IO.MemoryStream out of the ExportToStream function, it is that I used to get an IO.Stream as a result from the function and now I am getting back a FileStreamDeleteOnClose instead. This type, FileStreamDeleteOnClose then is not able to be cast to an IO.MemoryStream item.
The ExportToStream function is supposed to return an IO.Stream item and it no longer is, which is causing the whole issue. In the KBA article listed above states this:
However, that is not what I am getting back! An IO.Stream is what I need to get back, how can I get it?
Thank you,
Leah
Hi Don,
Yes, I am using SP 13 as well as Visual Studio 2012.
I have other code that calls the GetPDF function, which then as you can see calls the GenerateReport function. Before I updated to VS 2012 and Crystal Reports SP 13 this all worked properly. Nothing in the code has changed, but now the GetPDF function returns a type FileStreamDeleteOnClose instead of an IO.Stream.
''' <summary> Function GetPDF creates PDF of this form </summary>
''' <param name="genColsolidatedPDF"> = "Yes" if generating a Consolidated PDF </param>
''' <returns> IO.Stream </returns>
''' <remarks> The class must be instantiated before calling this method. </remarks>
Protected Friend Function GetPDF(ByVal genColsolidatedPDF As String) As IO.Stream
Return GenerateReport(genColsolidatedPDF).ExportToStream(ExportFormatType.PortableDocFormat)
End Function
''' <summary>
''' Generate report PDF for Consolidated PDF
''' </summary>
''' <param name="genConsolPDF"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function GenerateReport(ByVal genConsolPDF As String) As ReportDocument
Dim connInfo As New ConnectionInfo
Dim databaseLoginInfo As New TableLogOnInfos
Dim reportDoc As New ReportDocument
Dim tableSet As Tables
reportDoc = New ActiveSignatures
reportDoc.SetParameterValue(DAL.ParmName.MRId, BLL.SessionData.EssInfo.MRID)
reportDoc.SetParameterValue(cCONSOLIDATEPDF, genConsolPDF)
connInfo.ServerName = [Lib].ApplicationData.db_Server
connInfo.DatabaseName = [Lib].ApplicationData.db_Name
connInfo.UserID = [Lib].ApplicationData.db_UserId
connInfo.Password = [Lib].ApplicationData.db_Password
tableSet = reportDoc.Database.Tables
For Each singleTable As Table In tableSet
Dim singleTableLogoninfo As TableLogOnInfo = singleTable.LogOnInfo
singleTableLogoninfo.ConnectionInfo = connInfo
singleTable.ApplyLogOnInfo(singleTableLogoninfo)
Next
Return reportDoc
End Function
Please let me know if there is anything else you need to help resolve this issue.
Thank you,
Leah
Hi Leah,
I pinged the Developer about this questions and here is what he suggested to do:
From the code piece I could not see how customer dealt with the exported stream.
The problem now is not that I am trying to get an IO.MemoryStream
out of the ExportToStream function, it is that I used to get an IO.Stream as a
result from the function and now I am getting back a FileStreamDeleteOnClose
instead. This type, FileStreamDeleteOnClose then is not able to be cast
to an IO.MemoryStream item.
...At least following synchronized stream copy works well for writing a file:
ReportDocument rd=new ReportDocument();
rd.Load(rptPath);
//System.IO.MemoryStream exportStream = (MemoryStream)rd.ExportToStream(ExportFormatType.CharacterSeparatedValues);
System.IO.Stream exportStream = rd.ExportToStream(ExportFormatType.Xml);
using (FileStream fileStream = new FileStream(expPath, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
exportStream.CopyTo(fileStream);
fileStream.Dispose();
}
exportStream.Close();
Btw, if the exported file over 4GB will cause error, it’s a known limitation…
See if this helps.
Don
Hi Don,
I gave this a try and I got the same results I was getting before the change the ExportToStream is returning a object of type FileStreamDeleteOnclose instead of an object of type IO.Stream.
You have what I had before already, but here is what I changed it to in order to do what the developer asked:
Protected Friend Function GetPDF(ByVal genColsolidatedPDF As String) As IO.
Stream
Dim exportStream As System.IO.Stream = GenerateReport(genColsolidatedPDF).ExportToStream(ExportFormatType
.PortableDocFormat)
Using fileStream As New IO.FileStream(expPath, System.IO.FileMode.Create, System.IO.FileAccess
.Write)exportStream.CopyTo(fileStream)fileStream.Dispose()
exportStream.Close()
Return
exportStream
End Function
Private Function GenerateReport(ByVal genConsolPDF As String) As
ReportDocument
Dim connInfo As New
ConnectionInfo
Dim databaseLoginInfo As New
TableLogOnInfos
Dim reportDoc As New
ReportDocument
Dim tableSet As
Tables
reportDoc.Load(rptPath)
reportDoc.SetParameterValue(DAL.ParmName.MRId, BLL.SessionData
reportDoc.SetParameterValue(cCONSOLIDATEPDF, genConsolPDF)
connInfo.ServerName = [Lib].ApplicationData.db_Server
connInfo.DatabaseName = [Lib].ApplicationData.db_Name
connInfo.UserID = [Lib].ApplicationData.db_UserId
tableSet = reportDoc.Database.Tables
For Each singleTable As Table In
tableSet
Dim singleTableLogoninfo As TableLogOnInfo
= singleTable.LogOnInfo
singleTableLogoninfo.ConnectionInfo = connInfo
singleTable.ApplyLogOnInfo(singleTableLogoninfo)
Next
Return reportDoc
End Function
It seemed like the developer maybe wanted more information about how the report is then used, so this is what happens. The report is then supposed to be returned as type IO.Stream and then it is to be converted to an IO.MemoryStream:
Dim sourceFiles(sourceSize as MemoryStream)
sourceFiles(i) = New MemoryStream(GetByteArray(CType(parameters.SignaturePage, IO.MemoryStream)))
parameters.SignaturePage is the crytal report that is being returned, that is what needs to be IO.Stream, but is coming back as FileStreamDeleteOnclose.
When the application then tries to convert from FileStreamDeleteOnClose to IO.MemoryStream, that is where the error occurrs: Exception: System.InvalidCastException: Unable to cast object of type 'FileStreamDeleteOnClose' to type 'System.IO.MemoryStream'. But this is only occurring because I am getting back the incorrect object type from the ExportToStream call.
Before I upgraded to SP 13 this worked fine, and has been working fine for years. It is after SP13 that this ExportToStream stopped giving me the IO.Stream object type and is now returning the FileStreamDeleteOnClose.
I hope that helps!
Thank you,
Leah
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.