Have you ever looked at the generated code for a Strongly Typed (ST)
DataSet?  You will notice that the ST DataSet class has the
[Serializable()] attribute but the ST DataTables do not.  The
System.Data.DataSet and System.Data.DataTable classes are both marked
Serializable and Implement the ISerializable interface.  The derived ST
DataSet also has the Serializable attribute but you will notice that the
ST DataTables do not have the Serializable attribute.  A class that
Implements ISerializable (which both the ST DataSet and ST DataTables do
through inheritance) does not mean that it can be serialized.  It only
indicates that the default serialization is not to occur and that the
runtime is to call ISerializable::GetObjectData() to get the serialized
state of the object.  

The ST DataSet relies on the base class implementation of
ISerializable::GetObjectData() to perform the serialization and does not
provide any additional custom serialization.  The GetChanges() method on
the DataSet and DataTable returns an instance that is equivalent to
this.GetType().  Therefore, in the case of the ST DataSet, you are
getting back the ST DataSet in the GetChanges() call and the same goes
for the ST DataTable.  As stated above, the ST DataSet has the
[Serializable()] attribute and the ST DataTable does not.  This is why
you are experiencing the behavior you describing.  If you wish to have
your ST DataTables serializable, simply mark them with the
[Serializable()] attribute but remember the next time you make a change
to the XSD and the class generator does its thing, your changes will be
lost. 

Chad Gross

> -----Original Message-----
> From: Dan Green [SMTP:[EMAIL PROTECTED]]
> Sent: Saturday, June 22, 2002 5:59 PM
> To:   [EMAIL PROTECTED]
> Subject:           Re: [ADVANCED-DOTNET] Strongly Typed DataTables
> aren't             serializable - why?
> 
> Hi Mitch,
> 
> > The GetChanges() method doesn't actually serialize the DataSet
> > it clones it then does a bit of manual twiddling based on the
> > row states of the data. I guess you could grab the generated
> > code and make the necessary modifications yourself.
> 
> Thanks, but I'm still interested in why strongly typed datatables
> aren't
> marked serializable in the first place.
> 
> I'm also interested in the reason for the following curious
> behaviour...
> 
> When I used GetChanges() on a strongly typed *datatable* and then
> tried
> to send that object across a remoting boundary I received a
> serialization error.
> 
> When I used GetChanges() on the same datatable's strongly typed
> *dataset* I didn't receive a serialization error when sending the
> object
> across a remoting boundary.
> 
> I'm assuming the strongly typed dataset uses custom serialization that
> effectively ignores the absence of the serialization attribute on its
> associated strongly typed datatables.
> 
> 
> Dan Green
> [ http://dotnetdan.com -- putting the dan in .net ]
> 
> You can read messages from the Advanced DOTNET archive, unsubscribe
> from Advanced DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to