我想通过tcpclient从服务器发送一个对象到客户端,并且出现错误。首先,这里是包类:通过tcpclient发送序列化对象的问题
[Serializable()]
public class pack
{
public int a;
}
这里是服务器的发送代码(它的命名空间是WindowsFormsApplication1):
pack pachet = new pack();
pachet.a = 3;
IFormatter bformatter = new BinaryFormatter();
NetworkStream ntstream = tcpClient.GetStream();
bformatter.Serialize(ntstream, pachet);
和客户端的“翻译”的代码(它的命名空间是WindowsFormsApplication2):
NetworkStream strm = client.GetStream();
IFormatter bformatter = new BinaryFormatter();
pack nettmp = (pack)bformatter.Deserialize(strm);
和错误是:
serializationException was unhandeled. Unable to find assembly 'WindowsFormsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
有人能告诉我问题是什么吗?
好的..从我的理解,我需要用pack类制作一个.dll文件。我会研究出口/导入在XML然后。谢谢 – Alex 2010-11-01 08:06:26
@Badescu:那么,你现有的装配也会起作用。 (你也应该强烈地考虑下面的.NET命名约定,其中类型是Pascal的。) – 2010-11-01 09:46:16
感谢xml提示。我已经使用它,它工作得很好。 – Alex 2010-11-01 13:47:21