问题描述
我目前正在尝试通过TCP连接发送序列化对象,如下所示-
I am currently trying to send a serialized object over a TCP connection as follows -
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(clientStream, (Object)Assembly.LoadFrom("test.dll"));
其中clientStream是
where clientStream is
TcpClient tcpClient = (TcpClient)client;
NetworkStream clientStream = tcpClient.GetStream();
这是发送部分.但是谁能告诉我如何在客户端收到此消息(即在另一端反序列化)?
This is the sending part. But can anyone tell me how do I receive this on the client side (i.e. deserialize it on the other end)?
推荐答案
不要序列化程序集.通过将程序集加载为文件并将这些字节发送到另一端,即可发送程序集本身.
Don't serialize the assembly. Send the assembly itself just by loading it as a file and sending those bytes to the other side.
然后,当双方具有相同的代码时,通过序列化发送对象.我相信反序列化对象的AppDomain将必须具有相关的程序集(或至少可以加载).
Then, when both sides have the same code, send the object via serialization. I believe the AppDomain which deserializes the object will have to have the relevant assembly loaded (or at least available to be loaded).
这篇关于通过TCP传输程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!