Serializing a dataset inherited from a typed dataset

K

Kevin

In .Net 2.0 I have a dataset that inherits from a typed dataset
(created using the built in tools).

The typed dataset is serializable, and when I look at the source in the
generated vb class it has lots of stuff to do with serializing in it.
When I try to serialize it, it all works fine.

I would think that if I inherit from this typed dataset then it would
also inherit all the serializable stuff but it doesnt seem to. When I
try I get an error saying:

Type 'HHD_.MeterTree.ConsViewerDataset' in Assembly 'HHD_.MeterTree,
Version=1.0.0.1, Culture=neutral, PublicKeyToken=0b07967f4983a577' is
not marked as serializable.

i have read around and but most answers dont seem to relate inheriting
from a typed dataset and involve writing lots of code to implement
serializable, however this seems unnecessary as my base class has
everything I need surely!

I have added:
'<Serializable()> _

and

Public Overrides Sub GetObjectData(ByVal info As
System.Runtime.Serialization.SerializationInfo, ByVal context As
System.Runtime.Serialization.StreamingContext)
MyBase.GetSerializationData(info, context)
End Sub
to my inherited class
however now it goes into 'GetObjectData' but then comes up with the
error:
Member 'XmlDiffGram' was not found.

please, someone help me!!!

Thanks in advance.
Kevin
 
D

Dave Sexton

Hi Kevin,

You need the SerializableAttribute just like you stated, however, you don't
have to override GetObjectData. That method is for the ISerializable
interface, implemented by DataSet. Anyway, in your implementation you're
calling the wrong method on MyBase. It shouldn't be GetSerializationData,
it should be MyBase.GetObjectData, but you don't need the override anyway
unless your class needs to actually participate in the serialization
process.
 
K

Kevin

Thanks for your reply Dave. Not sure why I didn't make the correct
mybase call, but i read somewhere that that was the call i needed to
make.

Anyway that fixes it a little, but now I get a
The constructor to deserialize an object
of type [myDataSetExt] was not found.

Some further digging reveals that this is a known issue with inheriting
from strongly typed datasets:

http://groups.google.co.uk/group/mi...k.adonet/browse_thread/thread/43103a7439cad95

I am trying to modify a visualizer for datasets btw.
http://www.codeproject.com/dotnet/DataSet_Watch2.asp

Thanks for your help.
Kevin
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top