Serializing classes derived from dataset

Discussion in 'ASP .Net' started by Aidan Glendye, Jul 28, 2003.

  1. Hi,

    I am trying to store various objects within session. Due
    to the site being hosted in a web farm we are going to
    have to use either State Server or SQL Server to persist
    the data in session. All of the objects are classes which
    inherit from a typed dataset.

    Looking at MSDN I have found the following two (what I
    believe to be) relevent statements (from article Object
    Serialization in the .NET Framework):

    "Derived classes should call the GetObjectData method on
    the base object if the latter implements ISerializable"

    and

    "When you derive a new class from one that implements
    ISerializable, the derived class must implement both the
    constructor as well as the GetObjectData method if it has
    any variables that need to be serialized."

    Since the Dataset implements ISerializable the above
    statements indicate that I should override the
    GetObjectData method. However if I try and override this
    method I get a compile error stating:

    "sub 'GetObjectData' cannot be declared 'Overrides'
    because it does not override a sub in a base class."

    I am also unable to call the method GetObjectData on the
    base class as it is not accessible.

    The classes which I am trying to persist have their own
    properties, some of which are themselves objects which
    inherit from datasets.

    If I create a test class which inherits from a typed
    dataset, and which has two additional properites (named
    Property1 and Property2) the following XML is persisted:

    <?xml version="1.0" encoding="utf-16"?>
    <xs:schema id="dsTemp"
    targetNamespace="http://tempuri.org/dsTemp.xsd"
    xmlns:mstns="http://tempuri.org/dsTemp.xsd"
    xmlns="http://tempuri.org/dsTemp.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
    attributeFormDefault="qualified"
    elementFormDefault="qualified">
    <xs:element name="dsTemp" msdata:IsDataSet="true"
    msdata:property1="1" msdata:property2="Aidan">
    <xs:complexType>
    <xs:choice maxOccurs="unbounded">
    <xs:element name="InvoiceHeader">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="InvoiceHeaderID"
    msdata:ReadOnly="true" msdata:AutoIncrement="true"
    type="xs:int" />
    <xs:element name="POHeaderID" type="xs:int"
    minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    <xs:unique name="dsTempKey1" msdata:primaryKey="true">
    <xs:selector xpath=".//mstns:InvoiceHeader" />
    <xs:field xpath="mstns:InvoiceHeaderID" />
    </xs:unique>
    </xs:element>
    </xs:schema>

    Note that the properties have been serialized, but have
    been serialized as "<xs:element name="dsTemp"
    msdata:IsDataSet="true" msdata:property1="1"
    msdata:property2="Aidan">"

    I can find no way in which I can de-serialize these fields.

    Can someone please explain how I can have a class which
    inherits from a dataset, and which I can then serialize
    and de-serialize without losing the properties.

    Thanks in advance

    Aidan
    Aidan Glendye, Jul 28, 2003
    #1
    1. Advertising

  2. Note that the xml which should have been displayed
    indicated that the properties were included in a dataset
    element as

    msdata:property1="1"
    msdata:property2="Aidan"


    >-----Original Message-----
    >Hi,
    >
    >I am trying to store various objects within session. Due
    >to the site being hosted in a web farm we are going to
    >have to use either State Server or SQL Server to persist
    >the data in session. All of the objects are classes

    which
    >inherit from a typed dataset.
    >
    >Looking at MSDN I have found the following two (what I
    >believe to be) relevent statements (from article Object
    >Serialization in the .NET Framework):
    >
    >"Derived classes should call the GetObjectData method on
    >the base object if the latter implements ISerializable"
    >
    >and
    >
    >"When you derive a new class from one that implements
    >ISerializable, the derived class must implement both the
    >constructor as well as the GetObjectData method if it has
    >any variables that need to be serialized."
    >
    >Since the Dataset implements ISerializable the above
    >statements indicate that I should override the
    >GetObjectData method. However if I try and override this
    >method I get a compile error stating:
    >
    >"sub 'GetObjectData' cannot be declared 'Overrides'
    >because it does not override a sub in a base class."
    >
    >I am also unable to call the method GetObjectData on the
    >base class as it is not accessible.
    >
    >The classes which I am trying to persist have their own
    >properties, some of which are themselves objects which
    >inherit from datasets.
    >
    >If I create a test class which inherits from a typed
    >dataset, and which has two additional properites (named
    >Property1 and Property2) the following XML is persisted:
    >
    ><?xml version="1.0" encoding="utf-16"?>
    ><xs:schema id="dsTemp"
    >targetNamespace="http://tempuri.org/dsTemp.xsd"
    >xmlns:mstns="http://tempuri.org/dsTemp.xsd"
    >xmlns="http://tempuri.org/dsTemp.xsd"
    >xmlns:xs="http://www.w3.org/2001/XMLSchema"
    >xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
    >attributeFormDefault="qualified"
    >elementFormDefault="qualified">
    > <xs:element name="dsTemp" msdata:IsDataSet="true"
    >msdata:property1="1" msdata:property2="Aidan">
    > <xs:complexType>
    > <xs:choice maxOccurs="unbounded">
    > <xs:element name="InvoiceHeader">
    > <xs:complexType>
    > <xs:sequence>
    > <xs:element name="InvoiceHeaderID"
    >msdata:ReadOnly="true" msdata:AutoIncrement="true"
    >type="xs:int" />
    > <xs:element name="POHeaderID" type="xs:int"
    >minOccurs="0" />
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    > </xs:choice>
    > </xs:complexType>
    > <xs:unique name="dsTempKey1" msdata:primaryKey="true">
    > <xs:selector xpath=".//mstns:InvoiceHeader" />
    > <xs:field xpath="mstns:InvoiceHeaderID" />
    > </xs:unique>
    > </xs:element>
    ></xs:schema>
    >
    >Note that the properties have been serialized, but have
    >been serialized as "<xs:element name="dsTemp"
    >msdata:IsDataSet="true" msdata:property1="1"
    >msdata:property2="Aidan">"
    >
    >I can find no way in which I can de-serialize these

    fields.
    >
    >Can someone please explain how I can have a class which
    >inherits from a dataset, and which I can then serialize
    >and de-serialize without losing the properties.
    >
    >Thanks in advance
    >
    >Aidan
    >.
    >
    Aidan Glendye, Jul 28, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Goudie
    Replies:
    6
    Views:
    454
    Victor Bazarov
    Jan 26, 2004
  2. Manuel
    Replies:
    8
    Views:
    621
    Manuel
    Jan 5, 2006
  3. Replies:
    1
    Views:
    384
    myork
    May 23, 2007
  4. Replies:
    1
    Views:
    372
    Victor Bazarov
    May 23, 2007
  5. Serializing a derived class

    , Sep 12, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    115
Loading...

Share This Page