Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » General

Post new topic   Reply to topic
Mind Boggling Serialization Problem
View previous topic :: View next topic  
Author Message
bergy
Newbie


Joined: 05 Jan 2004
Posts: 1

PostPosted: Jan 5th, 2004 11:38 PM    Post subject: Mind Boggling Serialization Problem Reply with quote

When I try to load my Serialized object from a saved file it does this:

-------------------------
An unhandled exception of type
'System.Runtime.Serialization.SerializationException' occurred in
mscorlib.dll

Additional information: The constructor to deserialize an object of
type myNamespace.SmartObjects.Entry was not found.
-------------------------

Entry is another object that is called from the main object I'm trying to serialize. I have all my objects marked with <Serializable()>, it saves the object serialization flawlessly. The code errors here when I load it:

Code:
Dim note As Object = deserializer.Deserialize(myFileStream)


My Load Sub:
Code:


        Public Sub Load()
            If Me.FileLocation Is Nothing Then
                MsgBox("Filelocation not set to load.")
            Else
                Dim i As Integer
                Dim deserializer As New BinaryFormatter()
                Dim myFileStream As Stream = File.OpenRead(Me.FileLocation)
                Dim tempNote As New Notebook()
                Dim ex As Exception
                Dim note As Object = deserializer.Deserialize(myFileStream)
                'ERRORS RIGHT UP THERE ^^^^
                tempNote = CType(note, Notebook)
                myFileStream.Close()
                Me.Name = tempNote.Name
                Me.FileLocation = tempNote.FileLocation
            End If
        End Sub

My Save Sub:
Code:


        Public Sub Save()
            If Me.FileLocation Is Nothing Then
                MsgBox("Filelocation not set to save.")
            Else
                Dim myFileStream As Stream =File.Create(Me.FileLocation)
                Dim serializer As New BinaryFormatter()
                serializer.Serialize(myFileStream, Me)
                myFileStream.Close()
            End If
        End Sub


I was told this:
Quote:
Serialization can freak out at times if an object doesn't have a default constructor. I mean if the object does not have a constructor that takes no parameters.


So I added the below to all objects that didn't already have it. Still didn't work.
Code:
Public Sub New()

End Sub


Could someone give me a specific answer? I'll post my entire namespace if i must.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » General All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic