Object Serialization not working as expected 
Author Message
 Object Serialization not working as expected

Figured it out....
I had two problems...

1.  I was using varbinary in my database which requires an explicit size to
be set, used image fixed problem #1
2.  I was not calling my overloaded serialiazable constructor in my base
class for classes that inherited from
System.Collections.Specialized.NameObjectCollectionBase which already
implements iserializable..

works now...


Quote:
> Here's my report object in it's infancy.... I've added the serializable
> attribute on all of my components...  I've implemented ISerializable in my
> toplevel component, when I store the object in the database I see the size
> increase as I add more properties, when I deserialize the object I have no
> properties... I am unsure what the problem is... Do I need to call
Implement
> ISerializable and call GetObjectData in my collection classes... Here's my
> code... If this code looks right and you need the serialization and
> deserilaization methods sprocs or data schema I'll post anything else on
> request..

> Here's my serialization methods..

> Public Function DeSerializeQuery(ByVal intReportID As Integer) As WRQuery
> Dim objStream As New System.IO.MemoryStream()
> Dim objWriter As New
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
> Dim objDataReader As SqlDataReader
> Dim myDeserializedQuery As New WRQuery()
> Dim intContentSize As Integer
> Dim db As New MNC.Intranet.DataTools.Database()
> Dim params(0) As SqlParameter
> Try

> db.RunProcedure("DeSerializeReport", params, objDataReader)
> objDataReader.Read()
> intContentSize = CType(objDataReader("ContentSize"), Integer)
> If intContentSize <> 0 Then
> objStream.Write(CType(objDataReader("ReportObject"), Byte()), 0,
> UBound(CType(objDataReader("ReportObject"), Byte())) + 1)
> objStream.Seek(0, IO.SeekOrigin.Begin)
> myDeserializedQuery = CType(objWriter.Deserialize(objStream), WRQuery)
> End If
> objDataReader.Close()
> Catch e As Exception
> _errorMessage = "Unable to DeSerialize the query [" & e.Message & "]"
> Finally
> db = Nothing
> End Try
> Return myDeserializedQuery
> End Function
> Public Function SerializeQuery(ByVal intReportID As Integer, ByVal
objQuery
> As WRQuery) As Integer
> Dim objStream As New System.IO.MemoryStream()
> Dim objWriter As New
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
> Dim objBlob() As Byte
> objWriter.Serialize(objStream, objQuery)
> objBlob = objStream.ToArray
> Dim ContentSize As Integer = objBlob.Length
> Dim result As Integer
> Dim db As New MNC.Intranet.DataTools.Database()
> Dim params(2) As SqlParameter
> Try


> params(1).SqlDbType = SqlDbType.VarBinary

> result = db.RunProcedure("SerializeReport", params)
> If result <= 0 Then
> _errorMessage = db.ErrorMessage
> End If
> Catch e As Exception
> _errorMessage = "Unable to Serialize the query [" & e.Message & "]"
> result = -1
> Finally
> db = Nothing
> End Try
> Return result
> End Function



Tue, 07 Jun 2005 07:21:29 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Range.Collapse not working as expected

2. SetFocus Property on TextBox Does Not Work as Expected (Q237863)

3. Recorded Macro Does Not Work As Expected

4. Recorded Macro Does Not Work as Expected

5. ItemCheck event on Listviews not working as expected

6. Button and hotkey (do not work as expected)

7. Will Move command not working as expected

8. RegEnumValue API not working as I'd expect

9. Combo box and mousepointer not working as expected

10. Public Enum not working as expected

11. VB5 does not work as expected in a batch file

12. InStrRev not working as expected - bug?

 

 
Powered by phpBB® Forum Software