I am sending from my server to client an object of `Student` type which I serialize on the server side and deserialize on client side. The serialization and deserialization are as follows :
Expand|Select|Wrap|Line Numbers
- // server side serialization.
- Student s1 = new Student("Chuck","Noris");
- BinaryFormatter binaryFormatter = new BinaryFormatter();
- binaryFormatter.Serialize(writer.BaseStream, s1);
- // client side deserialization.
- 1.BinaryFormatter bin = new BinaryFormatter();
- 2.Student s1 = (Student)bin.Deserialize(receive.BaseStream);
- 3.Console.WriteLine(s1.ToString());
>[A]ServerClient.Student cannot be cast to [b]ServerClient.Student.
>Type A originates from 'Server, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in >the context 'Default' at location >D:\Faculty\Workspace\C#\ServerClient\ServerClient \Server.exe'. Type B originates from >Client, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at >location 'D:\Faculty\Workspace\C#\ServerClient\ServerClient \Client.exe'.
Also, if on the client side on line 2 I replace:
Expand|Select|Wrap|Line Numbers
- `Student s1 = (Student)bin.Deserialize(receive.BaseStream);`
Expand|Select|Wrap|Line Numbers
- Object s1 = bin.Deserialize(receive.BaseStream);
- Console.WriteLine(s1.ToString());
To create the Server.exe and Client.exe I used the following commands:
Expand|Select|Wrap|Line Numbers
- C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe Server.cs Repository.cs Student.cs
- C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe Client.cs Student.cs
Also my `Student` class have the `[Serialization]` attribute.
I did searched the web for this kind of errors but i couldn't find anything usefull.