bergy Newbie
Joined: 05 Jan 2004 Posts: 1
|
Posted: Jan 5th, 2004 11:38 PM Post subject: Mind Boggling Serialization Problem |
|
|
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. |
|