Network Serialization

R

Ray Mitchell

I'm trying to do serialization of an object across a
network. I'm getting an error when the client runs that
says: "Cannot find the assembly MyServer,
Version=1.0.1420.18327, Culture=neutral,
PublicKeyToken=null.
at
System.Runtime.Serialization.Formatters.Binary.BinaryAssemb
lyInfo.GetAssembly()"

MyServer is the name of my server project. First, why is
this error occurring and second, is the code below the
correct approach?

Thanks for all your help,
Ray Mitchell

SERVER CODE:
IPAddress ipAdr = Dns.Resolve("localhost").AddressList[0];
TcpListener server = new TcpListener(ipAdr, 10006);
server.Start();
TcpClient client = server.AcceptTcpClient();
BinaryWriter bWriter = new BinaryWriter((Stream)
client.GetStream());
BinaryFormatter bFormatter = new BinaryFormatter();
MyObject obj = new MyObject();
bFormatter.Serialize(bWriter.BaseStream, obj);

CLIENT CODE:
TcpClient client = new TcpClient("localhost", 10006);
BinaryReader bReader = new BinaryReader((Stream)
client.GetStream());
BinaryFormatter bFormatter = new BinaryFormatter();
MyObject obj = new MyObject();
obj = (MyObject)bFormatter.Deserialize(bReader.BaseStream);

THE OBJECT:
[Serializable]
public class MyObject
{
internal int objType;
internal string fname;
internal int length;
}
 
S

Sunny

Hi Ray,
MyObject class have to be implemented in a separate assembly, which you
have to reference both on server and on client.

More info you can find in the tread "Deserializing in a different
assembly... how to?" 2 hour ago in the same group

Sunny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top