我想通過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