[Mono-list] BinaryFormatter problem
Lluis Sanchez
lluis@ideary.com
Sun, 22 Jun 2003 14:24:40 +0200
> Hello,
>
> I am not sure wheter I am doing something wrong or it is a mono
> issue.( According to the mono status page,
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter is
> implemented)
>
> Could anybody please tell me why the last line of code throws an
> exception?
>
> TcpClient c ;
> try{
> c= new TcpClient("192.168.0.1",8080);
> }
> catch(SocketException e){
> ...
> }
> NetworkStream ns = c.GetStream();
> BinaryFormatter bf = new BinaryFormatter();
> PackageServerToClient p = (PackageServerToClient) bf.Deserialize(ns); <<
THROWS
>
>
> The last line throws:
>
> Unhandled Exception: System.InvalidCastException: Cannot cast from
source type
> to destination type in <0x000f3> 00 .Client:Main ()
>
>
> The server application had serialized the object like that:
>
> BinaryFormatter bf = new BinaryFormatter();
> bf.Serialize(ns,p);
>
>
> and the class PackageServerToClient has been declared with the
> [Serializable] attribute.
The only reason I can see with the available information is that what is
being deserialized from the network stream is not a PackageServerToClient
instance. To make sure, deserialize it as Object and check the type.
- Lluis
>
>
> Thanks for any help.
>
> Maurizio
>
>
>
> _______________________________________________
> Mono-list maillist - Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>