I am developing a client server application in C#.
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 :
// 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());
and i get this error at runtime:
[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:
Student s1 = (Student)bin.Deserialize(receive.BaseStream);
Object s1 = bin.Deserialize(receive.BaseStream); Console.WriteLine(s1.ToString());
everything works just fine, and the WriteLine method is printing toString represetation of object send it from server.
To create the Server.exe and Client.exe I used the following commands:
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
and I get no errors or warning.
Student class have the
I did searched the web for this kind of errors but i couldn't find anything usefull.