[Mono-list] BinaryFormatter Issue

Lluis Sanchez lluis@ximian.com
Mon, 29 Nov 2004 11:31:17 +0100


On ds, 2004-11-27 at 09:50 +0000, Pedro Santos wrote:
> On Sat, 2004-11-27 at 08:47 +0000, Pedro Santos wrote:
> > Hello. I Use BinaryFormatter to serialize an Object and it runs just
> > fine. However, when I desserialize it, I get the following exception:
> > 
> > "Serializable objects must be marked with the Serializable attribute"
> > 
> > Any help on this?
> 
> Well, using SoapFormatter I got a better expcetion Message and find out
> I neglected to use [Serializable] in a nested class. Is this a bug?

The bug is probably that the serialization process is not throwing the
exception.

> 
> However, now I have another problem. I get the following exception form
> either IFormatter:
> 
> System.Runtime.Serialization.SerializationException: The constructor to
> deserialize an object of type Chronos.Alliances.AllianceCollection was
> not found.
> 
> And I have AllianceCollection like this:
> 
> [Serializable]
> public class AllianceCollection : Hashtable {
> 
>         public AllianceCollection() {
>                 // ... some stuff
>         }
> };
> 
> Any help? If I create a ctor with the SerializationInfo and
> StreamingContext I have other several problems. What's the best way to
> serialize AllianceCollection?

Since hashtable implements custom serialization using the ISerializable
interface, you need to create the constructor with SerializationInfo and
StreamingContext, which would call the same constructor in the base
class.

> 
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list