I am stuck with a unique problem, I have a class whose object i need to convert to a byte[] to send it further.
I am using microsoft's Binaryformatter to convert object to byte[] as per given below.
But problem here is that the converted byte[] contains 245 bytes of value instead of 22 what the class actually should contain.
Expand|Select|Wrap|Line Numbers
- private byte[] ObjectToByteArray(Object obj)
- {
- if(obj == null)
- return null;
- BinaryFormatter bf = new BinaryFormatter();
- MemoryStream ms = new MemoryStream();
- bf.Serialize(ms, obj);
- return ms.ToArray();
- }
Thanks in Advance
Eric Haas.