Home All Groups Group Topic Archive Search About

ISerialization Frustration !

Author
12 Sep 2006 12:43 AM
vbMental
I'm not sure if I'm having a moment of non-clarity or not but I don't believe
implementing ISerialization works at all.

It started when I had a class that I wanted to provide my own serialization
for because it had ReadOnly properties. So I implemented the ISerializable
interface.
I through a breakpoint into the GetObjectData() method and the New(info,
context) constructor and the breakpoint was not hit.

At this point, I realized that the automatic serialization was being
performed and not the ISerialization interface. Here's sample code:

' This is the class that supposed to be "ISerializable"

Imports System.Runtime.Serialization
Imports System.Xml.Serialization

<Serializable()> _
Public Class SerializableObject
    Implements ISerializable

    Private _TestData As String
    Private _HiddenData As String

    Public Property TestData() As String
        Get
            Return _TestData
        End Get
        Set(ByVal value As String)
            _TestData = value
        End Set
    End Property

    Public Sub New()

    End Sub

    Protected Sub New(ByVal info As
System.Runtime.Serialization.SerializationInfo, ByVal context As
System.Runtime.Serialization.StreamingContext)
        'Try putting a breakpoint here, it won't be hit.
        _TestData = info.GetString("TestData")
        _HiddenData = info.GetString("HiddenData")
    End Sub

    Public Sub GetObjectData(ByVal info As
System.Runtime.Serialization.SerializationInfo, ByVal context As
System.Runtime.Serialization.StreamingContext) Implements
System.Runtime.Serialization.ISerializable.GetObjectData
        'Try putting a breakpoint here, it won't be hit.
        info.AddValue("TestData", _TestData, GetType(String))
        info.AddValue("HiddenData", "hidden", GetType(String))
    End Sub
End Class


Here's some code to test the serialization in the Form_Load event so you
don't have to click anything to test it:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        Dim s As New XmlSerializer(GetType(SerializableObject))
        Dim o As New SerializableObject
        o.TestData = "Test"

        'Serialize first.
        Dim sb As New System.Text.StringBuilder
        Dim sw As New StringWriter(sb)
        s.Serialize(sw, o)
        sw.Close()
        'Clear the object to make sure there's nothing up my sleeve.
        o = Nothing
        'Deserialize the object.
        Dim sr As New StringReader(sb.ToString)
        o = s.Deserialize(sr)
        TextBox1.Text = o.TestData

        'Take a look at the XML generated. You'll see that the property
called "Hidden" isn't there.
        'That means that custom serialization didn't run.
        MessageBox.Show(sb.ToString)

End Sub


If ANYONE knows what's going on and how I can get ISerialization to work for
me, please let me know. I've tried all the MSDN and google links to no avail.
Thanks.

Author
12 Sep 2006 2:01 AM
Lloyd Dupont
Haheum....

I don't know what is this 'ISerialization' you are talking about but let's
say the ISerializable is meant to be used with the BinaryFormate.

So I would say: Get rid if this XmlSerializer.

But I guess the issue is more like you want to use the XmlSerializer, so I
will recommend you read its documentation.
They mention things like XmlElementAttribute in it (and other things) which
you might find helpfull!

RTFM man!


Show quote
"vbMental" <vbMen***@discussions.microsoft.com> wrote in message
news:8E563C00-9D48-489D-8CFE-038CCBE8A402@microsoft.com...
> I'm not sure if I'm having a moment of non-clarity or not but I don't
> believe
> implementing ISerialization works at all.
>
> It started when I had a class that I wanted to provide my own
> serialization
> for because it had ReadOnly properties. So I implemented the ISerializable
> interface.
> I through a breakpoint into the GetObjectData() method and the New(info,
> context) constructor and the breakpoint was not hit.
>
> At this point, I realized that the automatic serialization was being
> performed and not the ISerialization interface. Here's sample code:
>
> ' This is the class that supposed to be "ISerializable"
>
> Imports System.Runtime.Serialization
> Imports System.Xml.Serialization
>
> <Serializable()> _
> Public Class SerializableObject
>    Implements ISerializable
>
>    Private _TestData As String
>    Private _HiddenData As String
>
>    Public Property TestData() As String
>        Get
>            Return _TestData
>        End Get
>        Set(ByVal value As String)
>            _TestData = value
>        End Set
>    End Property
>
>    Public Sub New()
>
>    End Sub
>
>    Protected Sub New(ByVal info As
> System.Runtime.Serialization.SerializationInfo, ByVal context As
> System.Runtime.Serialization.StreamingContext)
>        'Try putting a breakpoint here, it won't be hit.
>        _TestData = info.GetString("TestData")
>        _HiddenData = info.GetString("HiddenData")
>    End Sub
>
>    Public Sub GetObjectData(ByVal info As
> System.Runtime.Serialization.SerializationInfo, ByVal context As
> System.Runtime.Serialization.StreamingContext) Implements
> System.Runtime.Serialization.ISerializable.GetObjectData
>        'Try putting a breakpoint here, it won't be hit.
>        info.AddValue("TestData", _TestData, GetType(String))
>        info.AddValue("HiddenData", "hidden", GetType(String))
>    End Sub
> End Class
>
>
> Here's some code to test the serialization in the Form_Load event so you
> don't have to click anything to test it:
>
>    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>        Dim s As New XmlSerializer(GetType(SerializableObject))
>        Dim o As New SerializableObject
>        o.TestData = "Test"
>
>        'Serialize first.
>        Dim sb As New System.Text.StringBuilder
>        Dim sw As New StringWriter(sb)
>        s.Serialize(sw, o)
>        sw.Close()
>        'Clear the object to make sure there's nothing up my sleeve.
>        o = Nothing
>        'Deserialize the object.
>        Dim sr As New StringReader(sb.ToString)
>        o = s.Deserialize(sr)
>        TextBox1.Text = o.TestData
>
>        'Take a look at the XML generated. You'll see that the property
> called "Hidden" isn't there.
>        'That means that custom serialization didn't run.
>        MessageBox.Show(sb.ToString)
>
> End Sub
>
>
> If ANYONE knows what's going on and how I can get ISerialization to work
> for
> me, please let me know. I've tried all the MSDN and google links to no
> avail.
> Thanks.
Author
12 Sep 2006 2:13 AM
vbMental
Actually, it is "ISerializable" that I've implemented (what is ISerialization
anyway?)
But you're right, I suppose it should be IXMLSerializabble - NO THANKS TO
THE MSDN LIBRARY!. It says that IXMLSerializable is to be used internally
(etc..., etc..., etc...)

Show quote
"Lloyd Dupont" wrote:

> Haheum....
>
> I don't know what is this 'ISerialization' you are talking about but let's
> say the ISerializable is meant to be used with the BinaryFormate.
>
> So I would say: Get rid if this XmlSerializer.
>
> But I guess the issue is more like you want to use the XmlSerializer, so I
> will recommend you read its documentation.
> They mention things like XmlElementAttribute in it (and other things) which
> you might find helpfull!
>
> RTFM man!
>
>
> "vbMental" <vbMen***@discussions.microsoft.com> wrote in message
> news:8E563C00-9D48-489D-8CFE-038CCBE8A402@microsoft.com...
> > I'm not sure if I'm having a moment of non-clarity or not but I don't
> > believe
> > implementing ISerialization works at all.
> >
> > It started when I had a class that I wanted to provide my own
> > serialization
> > for because it had ReadOnly properties. So I implemented the ISerializable
> > interface.
> > I through a breakpoint into the GetObjectData() method and the New(info,
> > context) constructor and the breakpoint was not hit.
> >
> > At this point, I realized that the automatic serialization was being
> > performed and not the ISerialization interface. Here's sample code:
> >
> > ' This is the class that supposed to be "ISerializable"
> >
> > Imports System.Runtime.Serialization
> > Imports System.Xml.Serialization
> >
> > <Serializable()> _
> > Public Class SerializableObject
> >    Implements ISerializable
> >
> >    Private _TestData As String
> >    Private _HiddenData As String
> >
> >    Public Property TestData() As String
> >        Get
> >            Return _TestData
> >        End Get
> >        Set(ByVal value As String)
> >            _TestData = value
> >        End Set
> >    End Property
> >
> >    Public Sub New()
> >
> >    End Sub
> >
> >    Protected Sub New(ByVal info As
> > System.Runtime.Serialization.SerializationInfo, ByVal context As
> > System.Runtime.Serialization.StreamingContext)
> >        'Try putting a breakpoint here, it won't be hit.
> >        _TestData = info.GetString("TestData")
> >        _HiddenData = info.GetString("HiddenData")
> >    End Sub
> >
> >    Public Sub GetObjectData(ByVal info As
> > System.Runtime.Serialization.SerializationInfo, ByVal context As
> > System.Runtime.Serialization.StreamingContext) Implements
> > System.Runtime.Serialization.ISerializable.GetObjectData
> >        'Try putting a breakpoint here, it won't be hit.
> >        info.AddValue("TestData", _TestData, GetType(String))
> >        info.AddValue("HiddenData", "hidden", GetType(String))
> >    End Sub
> > End Class
> >
> >
> > Here's some code to test the serialization in the Form_Load event so you
> > don't have to click anything to test it:
> >
> >    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> >        Dim s As New XmlSerializer(GetType(SerializableObject))
> >        Dim o As New SerializableObject
> >        o.TestData = "Test"
> >
> >        'Serialize first.
> >        Dim sb As New System.Text.StringBuilder
> >        Dim sw As New StringWriter(sb)
> >        s.Serialize(sw, o)
> >        sw.Close()
> >        'Clear the object to make sure there's nothing up my sleeve.
> >        o = Nothing
> >        'Deserialize the object.
> >        Dim sr As New StringReader(sb.ToString)
> >        o = s.Deserialize(sr)
> >        TextBox1.Text = o.TestData
> >
> >        'Take a look at the XML generated. You'll see that the property
> > called "Hidden" isn't there.
> >        'That means that custom serialization didn't run.
> >        MessageBox.Show(sb.ToString)
> >
> > End Sub
> >
> >
> > If ANYONE knows what's going on and how I can get ISerialization to work
> > for
> > me, please let me know. I've tried all the MSDN and google links to no
> > avail.
> > Thanks.
>
>
>
Author
12 Sep 2006 4:04 AM
Lloyd Dupont
> Actually, it is "ISerializable" that I've implemented (what is
> ISerialization
> anyway?)
I don't know! It's just the title of your post, so you tell me!...

> But you're right, I suppose it should be IXMLSerializabble - NO THANKS TO
> THE MSDN LIBRARY!. It says that IXMLSerializable is to be used internally
> (etc..., etc..., etc...)
ungratefull one... tssk...

Show quote
>
> "Lloyd Dupont" wrote:
>
>> Haheum....
>>
>> I don't know what is this 'ISerialization' you are talking about but
>> let's
>> say the ISerializable is meant to be used with the BinaryFormate.
>>
>> So I would say: Get rid if this XmlSerializer.
>>
>> But I guess the issue is more like you want to use the XmlSerializer, so
>> I
>> will recommend you read its documentation.
>> They mention things like XmlElementAttribute in it (and other things)
>> which
>> you might find helpfull!
>>
>> RTFM man!
>>
>>
>> "vbMental" <vbMen***@discussions.microsoft.com> wrote in message
>> news:8E563C00-9D48-489D-8CFE-038CCBE8A402@microsoft.com...
>> > I'm not sure if I'm having a moment of non-clarity or not but I don't
>> > believe
>> > implementing ISerialization works at all.
>> >
>> > It started when I had a class that I wanted to provide my own
>> > serialization
>> > for because it had ReadOnly properties. So I implemented the
>> > ISerializable
>> > interface.
>> > I through a breakpoint into the GetObjectData() method and the
>> > New(info,
>> > context) constructor and the breakpoint was not hit.
>> >
>> > At this point, I realized that the automatic serialization was being
>> > performed and not the ISerialization interface. Here's sample code:
>> >
>> > ' This is the class that supposed to be "ISerializable"
>> >
>> > Imports System.Runtime.Serialization
>> > Imports System.Xml.Serialization
>> >
>> > <Serializable()> _
>> > Public Class SerializableObject
>> >    Implements ISerializable
>> >
>> >    Private _TestData As String
>> >    Private _HiddenData As String
>> >
>> >    Public Property TestData() As String
>> >        Get
>> >            Return _TestData
>> >        End Get
>> >        Set(ByVal value As String)
>> >            _TestData = value
>> >        End Set
>> >    End Property
>> >
>> >    Public Sub New()
>> >
>> >    End Sub
>> >
>> >    Protected Sub New(ByVal info As
>> > System.Runtime.Serialization.SerializationInfo, ByVal context As
>> > System.Runtime.Serialization.StreamingContext)
>> >        'Try putting a breakpoint here, it won't be hit.
>> >        _TestData = info.GetString("TestData")
>> >        _HiddenData = info.GetString("HiddenData")
>> >    End Sub
>> >
>> >    Public Sub GetObjectData(ByVal info As
>> > System.Runtime.Serialization.SerializationInfo, ByVal context As
>> > System.Runtime.Serialization.StreamingContext) Implements
>> > System.Runtime.Serialization.ISerializable.GetObjectData
>> >        'Try putting a breakpoint here, it won't be hit.
>> >        info.AddValue("TestData", _TestData, GetType(String))
>> >        info.AddValue("HiddenData", "hidden", GetType(String))
>> >    End Sub
>> > End Class
>> >
>> >
>> > Here's some code to test the serialization in the Form_Load event so
>> > you
>> > don't have to click anything to test it:
>> >
>> >    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>> > System.EventArgs) Handles MyBase.Load
>> >        Dim s As New XmlSerializer(GetType(SerializableObject))
>> >        Dim o As New SerializableObject
>> >        o.TestData = "Test"
>> >
>> >        'Serialize first.
>> >        Dim sb As New System.Text.StringBuilder
>> >        Dim sw As New StringWriter(sb)
>> >        s.Serialize(sw, o)
>> >        sw.Close()
>> >        'Clear the object to make sure there's nothing up my sleeve.
>> >        o = Nothing
>> >        'Deserialize the object.
>> >        Dim sr As New StringReader(sb.ToString)
>> >        o = s.Deserialize(sr)
>> >        TextBox1.Text = o.TestData
>> >
>> >        'Take a look at the XML generated. You'll see that the property
>> > called "Hidden" isn't there.
>> >        'That means that custom serialization didn't run.
>> >        MessageBox.Show(sb.ToString)
>> >
>> > End Sub
>> >
>> >
>> > If ANYONE knows what's going on and how I can get ISerialization to
>> > work
>> > for
>> > me, please let me know. I've tried all the MSDN and google links to no
>> > avail.
>> > Thanks.
>>
>>
>>
Author
12 Sep 2006 1:40 PM
vbMental
Ungrateful? No, not at all. Thank you (which I stated in advance in the
otiginal post) My dismay is with the MSDN library for it's lack of
documentation on IXMLSerializable.

Show quote
"Lloyd Dupont" wrote:

> > Actually, it is "ISerializable" that I've implemented (what is
> > ISerialization
> > anyway?)
> I don't know! It's just the title of your post, so you tell me!...
>
> > But you're right, I suppose it should be IXMLSerializabble - NO THANKS TO
> > THE MSDN LIBRARY!. It says that IXMLSerializable is to be used internally
> > (etc..., etc..., etc...)
> ungratefull one... tssk...
>
> >
> > "Lloyd Dupont" wrote:
> >
> >> Haheum....
> >>
> >> I don't know what is this 'ISerialization' you are talking about but
> >> let's
> >> say the ISerializable is meant to be used with the BinaryFormate.
> >>
> >> So I would say: Get rid if this XmlSerializer.
> >>
> >> But I guess the issue is more like you want to use the XmlSerializer, so
> >> I
> >> will recommend you read its documentation.
> >> They mention things like XmlElementAttribute in it (and other things)
> >> which
> >> you might find helpfull!
> >>
> >> RTFM man!
> >>
> >>
> >> "vbMental" <vbMen***@discussions.microsoft.com> wrote in message
> >> news:8E563C00-9D48-489D-8CFE-038CCBE8A402@microsoft.com...
> >> > I'm not sure if I'm having a moment of non-clarity or not but I don't
> >> > believe
> >> > implementing ISerialization works at all.
> >> >
> >> > It started when I had a class that I wanted to provide my own
> >> > serialization
> >> > for because it had ReadOnly properties. So I implemented the
> >> > ISerializable
> >> > interface.
> >> > I through a breakpoint into the GetObjectData() method and the
> >> > New(info,
> >> > context) constructor and the breakpoint was not hit.
> >> >
> >> > At this point, I realized that the automatic serialization was being
> >> > performed and not the ISerialization interface. Here's sample code:
> >> >
> >> > ' This is the class that supposed to be "ISerializable"
> >> >
> >> > Imports System.Runtime.Serialization
> >> > Imports System.Xml.Serialization
> >> >
> >> > <Serializable()> _
> >> > Public Class SerializableObject
> >> >    Implements ISerializable
> >> >
> >> >    Private _TestData As String
> >> >    Private _HiddenData As String
> >> >
> >> >    Public Property TestData() As String
> >> >        Get
> >> >            Return _TestData
> >> >        End Get
> >> >        Set(ByVal value As String)
> >> >            _TestData = value
> >> >        End Set
> >> >    End Property
> >> >
> >> >    Public Sub New()
> >> >
> >> >    End Sub
> >> >
> >> >    Protected Sub New(ByVal info As
> >> > System.Runtime.Serialization.SerializationInfo, ByVal context As
> >> > System.Runtime.Serialization.StreamingContext)
> >> >        'Try putting a breakpoint here, it won't be hit.
> >> >        _TestData = info.GetString("TestData")
> >> >        _HiddenData = info.GetString("HiddenData")
> >> >    End Sub
> >> >
> >> >    Public Sub GetObjectData(ByVal info As
> >> > System.Runtime.Serialization.SerializationInfo, ByVal context As
> >> > System.Runtime.Serialization.StreamingContext) Implements
> >> > System.Runtime.Serialization.ISerializable.GetObjectData
> >> >        'Try putting a breakpoint here, it won't be hit.
> >> >        info.AddValue("TestData", _TestData, GetType(String))
> >> >        info.AddValue("HiddenData", "hidden", GetType(String))
> >> >    End Sub
> >> > End Class
> >> >
> >> >
> >> > Here's some code to test the serialization in the Form_Load event so
> >> > you
> >> > don't have to click anything to test it:
> >> >
> >> >    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> >> > System.EventArgs) Handles MyBase.Load
> >> >        Dim s As New XmlSerializer(GetType(SerializableObject))
> >> >        Dim o As New SerializableObject
> >> >        o.TestData = "Test"
> >> >
> >> >        'Serialize first.
> >> >        Dim sb As New System.Text.StringBuilder
> >> >        Dim sw As New StringWriter(sb)
> >> >        s.Serialize(sw, o)
> >> >        sw.Close()
> >> >        'Clear the object to make sure there's nothing up my sleeve.
> >> >        o = Nothing
> >> >        'Deserialize the object.
> >> >        Dim sr As New StringReader(sb.ToString)
> >> >        o = s.Deserialize(sr)
> >> >        TextBox1.Text = o.TestData
> >> >
> >> >        'Take a look at the XML generated. You'll see that the property
> >> > called "Hidden" isn't there.
> >> >        'That means that custom serialization didn't run.
> >> >        MessageBox.Show(sb.ToString)
> >> >
> >> > End Sub
> >> >
> >> >
> >> > If ANYONE knows what's going on and how I can get ISerialization to
> >> > work
> >> > for
> >> > me, please let me know. I've tried all the MSDN and google links to no
> >> > avail.
> >> > Thanks.
> >>
> >>
> >>
>
>
>
Author
12 Sep 2006 11:21 PM
Lloyd Dupont
Ok, misunderstanding.. ;-)

I will add that I'm not uing MSDN but the Help application which comes with VS.NET / .NET SDK.
In the index tab, in the 'look for' text box you could type: 'XML serialization'
plenty of interesting reading there.

You will probably be interested in the subsection: "Attributes That Control XML Serialization"

Let me copy paste the array on this page:


      Attribute  Applies to  Specifies 
      XmlAnyAttributeAttribute
     Public field, property, parameter, or return value that returns an array of XmlAttribute objects.
     When deserializing, the array will be filled with XmlAttribute objects that represent all XML attributes unknown to the schema.

      XmlAnyElementAttribute
     Public field, property, parameter, or return value that returns an array of XmlElement objects.
     When deserializing, the array is filled with XmlElement objects that represent all XML elements unknown to the schema.

      XmlArrayAttribute
     Public field, property, parameter, or return value that returns an array of complex objects.
     The members of the array will be generated as members of an XML array.

      XmlArrayItemAttribute
     Public field, property, parameter, or return value that returns an array of complex objects.
     The derived types that can be inserted into an array. Usually applied in conjunction with an XmlArrayAttribute.

      XmlAttributeAttribute
     Public field, property, parameter, or return value.
     The member will be serialized as an XML attribute.

      XmlChoiceIdentifierAttribute
     Public field, property, parameter, or return value.
     The member can be further disambiguated by using an enumeration.

      XmlElementAttribute
     Public field, property, parameter, or return value.
     The field or property will be serialized as an XML element.

      XmlEnumAttribute
     Public field that is an enumeration identifier.
     The element name of an enumeration member.

      XmlIgnoreAttribute
     Public properties and fields.
     The property or field should be ignored when the containing class is serialized.

      XmlIncludeAttribute
     Public derived class declarations, and return values of public methods for Web Services Description Language (WSDL) documents.
     The class should be included when generating schemas (to be recognized when serialized).

      XmlRootAttribute
     Public class declarations.
     Controls XML serialization of the attribute target as an XML root element. Use the attribute to further specify the namespace and element name.

      XmlTextAttribute
     Public properties and fields.
     The property or field should be serialized as XML text.

      XmlTypeAttribute
     Public class declarations.
     The name and namespace of the XML type.





Show quote
"vbMental" <vbMen***@discussions.microsoft.com> wrote in message news:48E13631-02D1-4974-8FF1-960B01344E2D@microsoft.com...
> Ungrateful? No, not at all. Thank you (which I stated in advance in the
> otiginal post) My dismay is with the MSDN library for it's lack of
> documentation on IXMLSerializable.
>
> "Lloyd Dupont" wrote:
>
>> > Actually, it is "ISerializable" that I've implemented (what is
>> > ISerialization
>> > anyway?)
>> I don't know! It's just the title of your post, so you tell me!...
>>
>> > But you're right, I suppose it should be IXMLSerializabble - NO THANKS TO
>> > THE MSDN LIBRARY!. It says that IXMLSerializable is to be used internally
>> > (etc..., etc..., etc...)
>> ungratefull one... tssk...
>>
>> >
>> > "Lloyd Dupont" wrote:
>> >
>> >> Haheum....
>> >>
>> >> I don't know what is this 'ISerialization' you are talking about but
>> >> let's
>> >> say the ISerializable is meant to be used with the BinaryFormate.
>> >>
>> >> So I would say: Get rid if this XmlSerializer.
>> >>
>> >> But I guess the issue is more like you want to use the XmlSerializer, so
>> >> I
>> >> will recommend you read its documentation.
>> >> They mention things like XmlElementAttribute in it (and other things)
>> >> which
>> >> you might find helpfull!
>> >>
>> >> RTFM man!
>> >>
>> >>
>> >> "vbMental" <vbMen***@discussions.microsoft.com> wrote in message
>> >> news:8E563C00-9D48-489D-8CFE-038CCBE8A402@microsoft.com...
>> >> > I'm not sure if I'm having a moment of non-clarity or not but I don't
>> >> > believe
>> >> > implementing ISerialization works at all.
>> >> >
>> >> > It started when I had a class that I wanted to provide my own
>> >> > serialization
>> >> > for because it had ReadOnly properties. So I implemented the
>> >> > ISerializable
>> >> > interface.
>> >> > I through a breakpoint into the GetObjectData() method and the
>> >> > New(info,
>> >> > context) constructor and the breakpoint was not hit.
>> >> >
>> >> > At this point, I realized that the automatic serialization was being
>> >> > performed and not the ISerialization interface. Here's sample code:
>> >> >
>> >> > ' This is the class that supposed to be "ISerializable"
>> >> >
>> >> > Imports System.Runtime.Serialization
>> >> > Imports System.Xml.Serialization
>> >> >
>> >> > <Serializable()> _
>> >> > Public Class SerializableObject
>> >> >    Implements ISerializable
>> >> >
>> >> >    Private _TestData As String
>> >> >    Private _HiddenData As String
>> >> >
>> >> >    Public Property TestData() As String
>> >> >        Get
>> >> >            Return _TestData
>> >> >        End Get
>> >> >        Set(ByVal value As String)
>> >> >            _TestData = value
>> >> >        End Set
>> >> >    End Property
>> >> >
>> >> >    Public Sub New()
>> >> >
>> >> >    End Sub
>> >> >
>> >> >    Protected Sub New(ByVal info As
>> >> > System.Runtime.Serialization.SerializationInfo, ByVal context As
>> >> > System.Runtime.Serialization.StreamingContext)
>> >> >        'Try putting a breakpoint here, it won't be hit.
>> >> >        _TestData = info.GetString("TestData")
>> >> >        _HiddenData = info.GetString("HiddenData")
>> >> >    End Sub
>> >> >
>> >> >    Public Sub GetObjectData(ByVal info As
>> >> > System.Runtime.Serialization.SerializationInfo, ByVal context As
>> >> > System.Runtime.Serialization.StreamingContext) Implements
>> >> > System.Runtime.Serialization.ISerializable.GetObjectData
>> >> >        'Try putting a breakpoint here, it won't be hit.
>> >> >        info.AddValue("TestData", _TestData, GetType(String))
>> >> >        info.AddValue("HiddenData", "hidden", GetType(String))
>> >> >    End Sub
>> >> > End Class
>> >> >
>> >> >
>> >> > Here's some code to test the serialization in the Form_Load event so
>> >> > you
>> >> > don't have to click anything to test it:
>> >> >
>> >> >    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>> >> > System.EventArgs) Handles MyBase.Load
>> >> >        Dim s As New XmlSerializer(GetType(SerializableObject))
>> >> >        Dim o As New SerializableObject
>> >> >        o.TestData = "Test"
>> >> >
>> >> >        'Serialize first.
>> >> >        Dim sb As New System.Text.StringBuilder
>> >> >        Dim sw As New StringWriter(sb)
>> >> >        s.Serialize(sw, o)
>> >> >        sw.Close()
>> >> >        'Clear the object to make sure there's nothing up my sleeve.
>> >> >        o = Nothing
>> >> >        'Deserialize the object.
>> >> >        Dim sr As New StringReader(sb.ToString)
>> >> >        o = s.Deserialize(sr)
>> >> >        TextBox1.Text = o.TestData
>> >> >
>> >> >        'Take a look at the XML generated. You'll see that the property
>> >> > called "Hidden" isn't there.
>> >> >        'That means that custom serialization didn't run.
>> >> >        MessageBox.Show(sb.ToString)
>> >> >
>> >> > End Sub
>> >> >
>> >> >
>> >> > If ANYONE knows what's going on and how I can get ISerialization to
>> >> > work
>> >> > for
>> >> > me, please let me know. I've tried all the MSDN and google links to no
>> >> > avail.
>> >> > Thanks.
>> >>
>> >>
>> >>
>>
>>
>>
Author
12 Sep 2006 8:24 AM
Jeff Gaines
On 12/09/2006 in message
<8E563C00-9D48-489D-8CFE-038CCBE8A***@microsoft.com> vbMental wrote:

>'Take a look at the XML generated. You'll see that the property
>called "Hidden" isn't there.
>         'That means that custom serialization didn't run.
>         MessageBox.Show(sb.ToString)
>
>End Sub
>
>
>If ANYONE knows what's going on and how I can get ISerialization to work
>for
>me, please let me know. I've tried all the MSDN and google links to no
>avail.
>Thanks.

Doesn't Serialisation only serialise public properties/variables? I'm sure
when I was looking at it once I got an error that there were no public
(something, can't remember) to serialise.

--
Jeff Gaines
Author
12 Sep 2006 1:42 PM
vbMental
Jeff - it will supposedly automatically serialize public properties unless
you implement ISerializable and serialize/deserialize only the data you
choose.

Show quote
"Jeff Gaines" wrote:

> On 12/09/2006 in message
> <8E563C00-9D48-489D-8CFE-038CCBE8A***@microsoft.com> vbMental wrote:
>
> >'Take a look at the XML generated. You'll see that the property
> >called "Hidden" isn't there.
> >         'That means that custom serialization didn't run.
> >         MessageBox.Show(sb.ToString)
> >
> >End Sub
> >
> >
> >If ANYONE knows what's going on and how I can get ISerialization to work
> >for
> >me, please let me know. I've tried all the MSDN and google links to no
> >avail.
> >Thanks.
>
> Doesn't Serialisation only serialise public properties/variables? I'm sure
> when I was looking at it once I got an error that there were no public
> (something, can't remember) to serialise.
>
> --
> Jeff Gaines
>
Author
12 Sep 2006 1:46 PM
vbMental
Following up on my original post:

The reason it was not executing my ISerializable code was because I
should've been implementing IXMLSerializable which I ofcourse didn't find out
in the MSDN. Actually MSDN states that IXMLSerializable is not for public use
and the documentation ended there (atleast in MSDN 01-2006). BAD MSDN! BAD
BAD MSDN!

AddThis Social Bookmark Button