Solved

End of Stream encountered before parsing was completed.

Posted on 2006-07-12
14
969 Views
Last Modified: 2012-06-22
hi experts

i want to save my ReportDocument object in file for this purpose i am using serialization concept my code is working fine for serializing the object look at the below code

                   Dim s As New System.IO.FileStream("C:\object.txt", IO.FileMode.Create)
                    Dim f As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
                    f.Serialize(s, rptDoc)
                    s.Close()

but when i try to deserialize it. it generates error "End of Stream encountered before parsing was completed." look at the below code and tell me where i am wrong
                    Dim s = New System.IO.FileStream("C:\object.txt", IO.FileMode.Open)
                    Dim f As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
                    rptDoc = CType(f.Deserialize(s), ReportDocument)
                    s.close()

thanks,
ahmad
0
Comment
Question by:imrancs
  • 6
  • 6
14 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17090231
Ahmad,

Did the ReportDocument change between the time that you serialized it, and when you deserialized it?

Bob
0
 
LVL 10

Author Comment

by:imrancs
ID: 17106651
Hi Bob
i creates a new ReportDocument object before deserialize time. look at the below code

Dim rptDoc as new ReportDocument
 Dim s = New System.IO.FileStream("C:\object.txt", IO.FileMode.Open)
                    Dim f As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
                    rptDoc = CType(f.Deserialize(s), ReportDocument)
                    s.close()
Thanks,
Ahmad
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17107947
Did you compare the size of the file, with the expected size of the serializated text, to see if any extra characters are added to the text file, that would confuse the deserializer?

Bob
0
 
LVL 10

Author Comment

by:imrancs
ID: 17120211
Bob

How can compare it and how can i check file for extra characters.

thanks,
ahmad
0
 
LVL 10

Author Comment

by:imrancs
ID: 17120355
Bob

I have resolved this problem but now i am gettin following error at deserialize time.

Exception has been thrown by the target of an invocation.

have any idea why i am getting.

thanks,
ahmad
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17120880
First, what was your solution?  What was the problem?

Bob
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Author Comment

by:imrancs
ID: 17128450
Hi Bob

I was saving object in txt file when i saved it in doc or dat file then it worked fine. Now i am getting error
Exception has been thrown by the target of an invocation.
inner exception is
RAS is not running

RAS server is very expensive so we cant use it. can i store my object some other and better ways.

its very urgent

thanks,
ahmad
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17129223
Are you looking for somewhere besides a database, like SQL Server or Oracle?

Bob
0
 
LVL 10

Author Comment

by:imrancs
ID: 17136684
Hi Bob

I am using SQL Server and i have already try to store my object in database in binary form. but when i try to use it again then it generates error at converting it to reportdocument object. problem in casting and also deserializing.
you have any idea where i am wrong.

thanks,
ahmad
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17137610
Here is a class for working with SQL Server and BLOBs:

Imports System.Data.SqlClient

Public Class SqlServerBlobs

  Private m_connectString As String = String.Empty
  Private m_builderSQL As SqlCommandBuilder
  Private m_adapterDatabase As SqlDataAdapter
  Private m_dataResult As DataTable


  Public Sub New(ByVal connectString As String)

    ' Test for invalid parameters.
    If connectString.Length = 0 Then
      Throw New ArgumentNullException("Connection string is empty")
    End If

    m_connectString = connectString

  End Sub  'New(connect)


  Private Sub GetColumnData(ByVal table As String, ByVal column As String)

    ' Test for invalid parameters.
    If table.Length = 0 Then
      Throw New ArgumentNullException("Table name is empty")
    End If

    If column.Length = 0 Then
      Throw New ArgumentNullException("Column name is empty")
    End If

    ' Initialize the Select query text
    ' Example:
    '   Select image_data
    '     From ImageLibrary_Table
    Dim commandText As String = String.Format("Select {0} From {1}", column, table)

    ' Create an adapter to perform the Get operation.
    m_adapterDatabase = New SqlDataAdapter(commandText, m_connectString)
    m_adapterDatabase.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Generate InsertCommand and UpdateCommand from the SelectCommand.
    m_builderSQL = New SqlCommandBuilder(m_adapterDatabase)

    ' Create a new DataSet for the column data.
    m_dataResult = New DataTable

    ' Get the column data.
    m_adapterDatabase.Fill(m_dataResult)

  End Sub

  Public Sub InsertBlobData(ByVal table As String, _
   ByVal column As String, ByVal data As Byte())

    ' Open the table, and get a DataSet representing the
    ' Blob column.
    Me.GetColumnData(table, column)

    ' Insert the data.
    Dim newRow As DataRow = m_dataResult.NewRow()
    newRow(column) = data
    m_dataResult.Rows.Add(newRow)

    ' Write the new data to the database.
    m_adapterDatabase.Update(m_dataResult)

  End Sub

  Public Function ReadBlobData(ByVal table As String, ByVal column As String, _
   ByVal filter As String) As Byte()

    ' Open the table, and get a DataSet representing the
    ' Blob column.
    Me.GetColumnData(table, "*")

    ' Find the right record based on the filter expression.
    Dim rowFind As DataRow() = m_dataResult.Select(filter)

    If rowFind.Length > 0 Then
      ' The data from the field is a byte array, so an implicit conversion occurs here.
      Return rowFind(0)(column)
    End If

  End Function

End Class

Bob
0
 
LVL 10

Author Comment

by:imrancs
ID: 17146263
Hi Bob

My actual problem is not storing object in database. actually my problem is that i am storing my reportdocument object in binary form. it works fine but when again i try to use it and convert it from binary to reportdocument it prompts error binary can not be converted in reportdocument or some other. look at below

rpt = CType(arr, ReportDocument)
error:"F:\Serialization\EricMoreau\DemoCode\Form1.vb(353): Value of type '1-dimensional array of Byte' cannot be converted to 'CrystalDecisions.CrystalReports.Engine.ReportDocument'."

thanks,
ahmad
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17151003
Aah, yes, you are having problems with Eric Moreau's code.

Here is a link to his information, with an option to email him:

http://www.utmag.com/wconnect/wc.dll?9,7,10,1702

Bob
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now