Serialization of Collection in VB.NET 
Author Message
 Serialization of Collection in VB.NET

I need to make a custom class that contains Collection serializable.
Clearly, making the class as
<Serializable()> _ is not sufficient as Collection does not support
ISerializable.

Unfortunately, the matter is made worse by the fact that sometimes callers
of the collection need access by Key (which suggest Hashtable would be a
good alternative, implementing both IDictionary and ISerializable).
However, other callers need access by Index (which make ArrayList a good
alternative, implementing both IList and ISerializable). Other times,
callers use it as an Enumeration, which is fine, as both collections
implement IEnumerable.  But so far I couldn't find a native .NET class that
implements.
ISerializable
IEnumerable
IDictionary
IList

What is the simplest Collection I could use?  How could I set up creating my
own Collection which 'implements' all these interfaces (without having to
write too much code)?

FYI, I need to make the class serilizable, because it needs to be passed
between domains.



Tue, 20 Sep 2005 17:33:20 GMT  
 Serialization of Collection in VB.NET
Have you actually tried to use the collection classes and gotten an error?
Let us know what the error message you are see is if you are getting one.

You do not have to implement ISerializable to be serializable.  Only having
the (pseudo) attribute is sufficient.  For example ArrayList is marked as
serializable even though it does not explicitly implement the interface
Here is the first line of the IL for ArrayList

.class public auto ansi serializable beforefieldinit ArrayList

Jeremy Samples


Quote:
> I need to make a custom class that contains Collection serializable.
> Clearly, making the class as
> <Serializable()> _ is not sufficient as Collection does not support
> ISerializable.

> Unfortunately, the matter is made worse by the fact that sometimes callers
> of the collection need access by Key (which suggest Hashtable would be a
> good alternative, implementing both IDictionary and ISerializable).
> However, other callers need access by Index (which make ArrayList a good
> alternative, implementing both IList and ISerializable). Other times,
> callers use it as an Enumeration, which is fine, as both collections
> implement IEnumerable.  But so far I couldn't find a native .NET class
that
> implements.
> ISerializable
> IEnumerable
> IDictionary
> IList

> What is the simplest Collection I could use?  How could I set up creating
my
> own Collection which 'implements' all these interfaces (without having to
> write too much code)?

> FYI, I need to make the class serilizable, because it needs to be passed
> between domains.



Tue, 20 Sep 2005 21:02:34 GMT  
 Serialization of Collection in VB.NET
Collection objects are not serializable, you have to may 2 separate
interfaces to replace it.  I have an example of how to make a serializable
collection in my revLog application on my web site

http://members.lycos.co.uk/nickpatemanpwp/

Goto the "My Software" section and the "revLog", the source code is
available as well as the binaries.  I hope this helps

Nick.


Quote:
> Have you actually tried to use the collection classes and gotten an error?
> Let us know what the error message you are see is if you are getting one.

> You do not have to implement ISerializable to be serializable.  Only
having
> the (pseudo) attribute is sufficient.  For example ArrayList is marked as
> serializable even though it does not explicitly implement the interface
> Here is the first line of the IL for ArrayList

> .class public auto ansi serializable beforefieldinit ArrayList

> Jeremy Samples



> > I need to make a custom class that contains Collection serializable.
> > Clearly, making the class as
> > <Serializable()> _ is not sufficient as Collection does not support
> > ISerializable.

> > Unfortunately, the matter is made worse by the fact that sometimes
callers
> > of the collection need access by Key (which suggest Hashtable would be a
> > good alternative, implementing both IDictionary and ISerializable).
> > However, other callers need access by Index (which make ArrayList a good
> > alternative, implementing both IList and ISerializable). Other times,
> > callers use it as an Enumeration, which is fine, as both collections
> > implement IEnumerable.  But so far I couldn't find a native .NET class
> that
> > implements.
> > ISerializable
> > IEnumerable
> > IDictionary
> > IList

> > What is the simplest Collection I could use?  How could I set up
creating
> my
> > own Collection which 'implements' all these interfaces (without having
to
> > write too much code)?

> > FYI, I need to make the class serilizable, because it needs to be passed
> > between domains.



Wed, 21 Sep 2005 00:41:54 GMT  
 Serialization of Collection in VB.NET
Ok, we are talking about two different things here.  You are talking about
the backwards compatability Collection object.  We should not be using that
anymore, because it could be removed at any time.

I was talking about the System.Collections namespace classes.  If you look
at the System.Collections namespace you will see a much richer set of
classes anyway.  Most of the System.Collections classes are serializable as
is documented by MSDN and can be proven with code samples.  CollectionBase,
DictionaryBase, and even Hashtable are all marked as serializable.

Now back to the original question.  I think you might want to look at
DictionaryBase and add in support for IList in your derived class, if you
must really support that functionality.

Jeremy Samples


Quote:
> Collection objects are not serializable, you have to may 2 separate
> interfaces to replace it.  I have an example of how to make a serializable
> collection in my revLog application on my web site

> http://members.lycos.co.uk/nickpatemanpwp/

> Goto the "My Software" section and the "revLog", the source code is
> available as well as the binaries.  I hope this helps

> Nick.



> > Have you actually tried to use the collection classes and gotten an
error?
> > Let us know what the error message you are see is if you are getting
one.

> > You do not have to implement ISerializable to be serializable.  Only
> having
> > the (pseudo) attribute is sufficient.  For example ArrayList is marked
as
> > serializable even though it does not explicitly implement the interface
> > Here is the first line of the IL for ArrayList

> > .class public auto ansi serializable beforefieldinit ArrayList

> > Jeremy Samples



> > > I need to make a custom class that contains Collection serializable.
> > > Clearly, making the class as
> > > <Serializable()> _ is not sufficient as Collection does not support
> > > ISerializable.

> > > Unfortunately, the matter is made worse by the fact that sometimes
> callers
> > > of the collection need access by Key (which suggest Hashtable would be
a
> > > good alternative, implementing both IDictionary and ISerializable).
> > > However, other callers need access by Index (which make ArrayList a
good
> > > alternative, implementing both IList and ISerializable). Other times,
> > > callers use it as an Enumeration, which is fine, as both collections
> > > implement IEnumerable.  But so far I couldn't find a native .NET class
> > that
> > > implements.
> > > ISerializable
> > > IEnumerable
> > > IDictionary
> > > IList

> > > What is the simplest Collection I could use?  How could I set up
> creating
> > my
> > > own Collection which 'implements' all these interfaces (without having
> to
> > > write too much code)?

> > > FYI, I need to make the class serilizable, because it needs to be
passed
> > > between domains.



Wed, 21 Sep 2005 07:47:13 GMT  
 Serialization of Collection in VB.NET
Sorry, didn't mean to offend at all.  I didnt read it correctly.

Nick.


Quote:
> Ok, we are talking about two different things here.  You are talking about
> the backwards compatability Collection object.  We should not be using
that
> anymore, because it could be removed at any time.

> I was talking about the System.Collections namespace classes.  If you look
> at the System.Collections namespace you will see a much richer set of
> classes anyway.  Most of the System.Collections classes are serializable
as
> is documented by MSDN and can be proven with code samples.
CollectionBase,
> DictionaryBase, and even Hashtable are all marked as serializable.

> Now back to the original question.  I think you might want to look at
> DictionaryBase and add in support for IList in your derived class, if you
> must really support that functionality.

> Jeremy Samples



> > Collection objects are not serializable, you have to may 2 separate
> > interfaces to replace it.  I have an example of how to make a
serializable
> > collection in my revLog application on my web site

> > http://members.lycos.co.uk/nickpatemanpwp/

> > Goto the "My Software" section and the "revLog", the source code is
> > available as well as the binaries.  I hope this helps

> > Nick.



> > > Have you actually tried to use the collection classes and gotten an
> error?
> > > Let us know what the error message you are see is if you are getting
> one.

> > > You do not have to implement ISerializable to be serializable.  Only
> > having
> > > the (pseudo) attribute is sufficient.  For example ArrayList is marked
> as
> > > serializable even though it does not explicitly implement the
interface
> > > Here is the first line of the IL for ArrayList

> > > .class public auto ansi serializable beforefieldinit ArrayList

> > > Jeremy Samples



> > > > I need to make a custom class that contains Collection serializable.
> > > > Clearly, making the class as
> > > > <Serializable()> _ is not sufficient as Collection does not support
> > > > ISerializable.

> > > > Unfortunately, the matter is made worse by the fact that sometimes
> > callers
> > > > of the collection need access by Key (which suggest Hashtable would
be
> a
> > > > good alternative, implementing both IDictionary and ISerializable).
> > > > However, other callers need access by Index (which make ArrayList a
> good
> > > > alternative, implementing both IList and ISerializable). Other
times,
> > > > callers use it as an Enumeration, which is fine, as both collections
> > > > implement IEnumerable.  But so far I couldn't find a native .NET
class
> > > that
> > > > implements.
> > > > ISerializable
> > > > IEnumerable
> > > > IDictionary
> > > > IList

> > > > What is the simplest Collection I could use?  How could I set up
> > creating
> > > my
> > > > own Collection which 'implements' all these interfaces (without
having
> > to
> > > > write too much code)?

> > > > FYI, I need to make the class serilizable, because it needs to be
> passed
> > > > between domains.



Wed, 21 Sep 2005 16:31:26 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Collection content serialization: bug in VB?

2. Returning Dataset to ASP.NET from .NET Component / Business Object Serialization

3. XML Serialization problem with collections

4. Collection Serialization

5. Custom Collections in VB.NET

6. VB.NET collection object references messed up?

7. Collection Classes in VB.NET

8. Build Collection with VB.NET

9. forms collection in vb.net

10. How can I perform forms collection in VB.NET

 

 
Powered by phpBB® Forum Software