Trouble Serializing an Object

  • Thread starter Thread starter Boban Dragojlovic
  • Start date Start date
B

Boban Dragojlovic

For debug purposes, I need to occasionally dump an object to disk.

I wrote a method that looks like this:

Public sub Dump2Disk()
Dim formatter As New
System.Runtime.Serialization.Formatters.Soap.SoapFormatter

Dim stream As System.IO.FileStream
Try
stream = File.Open(String.Format("c:\{0}.xml", Now.ToFileTime),
FileMode.Create)
formatter.Serialize(stream, Me)
Catch ex As Exception
Finally
If Not stream Is Nothing Then
stream.Close()
End If
End Try

End sub


But whether I try the SoapFormatter, or the BinaryFormatter, I get
essentially an empty file (I get the file headers, but none of the
variables).


The object ('Me') that I'm trying to dump has a number of variables, as well
as objects and structure variables. Nothing appears.


If I dump a single "simple" variable
(e.g. Formatter.Serialize(Stream, Me.SomeVariable)

then I will get just that variable



How can I get the entire object (ME) along with all that it owns?
 
Landley said:
1. Is "ME" serializable and has the Serializable attribute been used?
2. Are the variables used public?
3. Is the GetObjectData method fully implemented? and for deserializing,
the New constructor?

----- Boban Dragojlovic wrote: -----

For debug purposes, I need to occasionally dump an object to disk.

I wrote a method that looks like this:

Public sub Dump2Disk()
Dim formatter As New
System.Runtime.Serialization.Formatters.Soap.SoapFormatter

Dim stream As System.IO.FileStream
Try
stream = File.Open(String.Format("c:\{0}.xml",
Now.ToFileTime),
FileMode.Create)
formatter.Serialize(stream, Me)
Catch ex As Exception
Finally
If Not stream Is Nothing Then
stream.Close()
End If
End Try

End sub


But whether I try the SoapFormatter, or the BinaryFormatter, I get
essentially an empty file (I get the file headers, but none of the
variables).


The object ('Me') that I'm trying to dump has a number of variables,
as well
as objects and structure variables. Nothing appears.


If I dump a single "simple" variable
(e.g. Formatter.Serialize(Stream, Me.SomeVariable)

then I will get just that variable



How can I get the entire object (ME) along with all that it owns?
One more caveat, a SOAP serializer only serialized Public stuff.
 
Back
Top