I have problem with C# .Net and I think you can help.
I make socket programming between client-server. I want to serialize
objects and send them from the server to client.
Any time I make this, exception happens when the sender deserialize
the object. that has been sent by the server
//struct to be serialized
[serializable()]
public struct port_data : ISerializable
{
//public int PortNo;
public string ProcessName;
// public int ProcessId;
//public string StrState;
//DeSerialization constructor
public port_data(SerializationInfo info, StreamingContext context)
{
//PortNo = (int)info.GetValue("PortNumber", typeof(int));
ProcessName = (string)info.GetValue("Processnm", typeof(string));
//ProcessId = (int)info.GetValue("PID", typeof(int));
//StrState = (string)info.GetValue("State", typeof(string));
}
///server code
port_data wmidata = new port_data ();
Stream stream = File.Open("EmployeeInfo.osl", FileMode.Create);
BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Serialize(stream, wmidata);
stream.Close();
/////
FileInfo finf = new FileInfo("EmployeeInfo.osl");
FileStream fs2 = new FileStream("EmployeeInfo.osl", FileMode.Open, FileAccess.Read);
byte[] fileInBytes = new byte[finf.Length];
fs2.Read(fileInBytes, 0, (int)finf.Length);
fs2.Close(); fs2 = null;
m_clientSocket.Send(fileInBytes);
StopSocketListener();
///client code
Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clientSocket.Connect(new IPEndPoint(IPAddress.Parse(ipaddress), 5300));
clientSocket.Send(Encoding.ASCII.GetBytes("start" + "\r\n"));
byte[] data = new byte[RcvdDataSize];// 10 KB
clientSocket.Receive(data);
FileStream filestream = new FileStream("NewInfo.osl", FileMode.Create, FileAccess.ReadWrite);
filestream.Write(data, 0, (int)data.Length);
filestream.Close(); filestream = null;
//Open the file written above and read values from it.
Stream stream = File.Open("NewInfo.osl", FileMode.Open);
BinaryFormatter bformatter = new BinaryFormatter();
port_data dd = (port_data)bformatter.Deserialize(stream);
stream.Close();
clientSocket.Close();
i have an exception at the red line,,obejct couldn't be deserialized :blink:
exception ::::
Unable to find assembly 'TCPService, Version=1.0.2380.9382, Culture=neutral, PublicKeyToken=null'.
where TCPService is the name of the server program