0

enter image description here

I am trying to create a byte array from the object. I have clone it but still encounter this exception. What is the problem here?

    class ByteInteract
    {
        Object tempObj;
        
        public ByteInteract(DataObj obj)
        {
            tempObj = (Object)obj.Clone();
        }

        public byte[] ToByteArray()
        {
            if (tempObj == null)
                return null;
            
            BinaryFormatter bf = new BinaryFormatter();
            
            using (MemoryStream ms = new MemoryStream())
            {
                lock (tempObj)
                {
                    ms.Flush();
                    bf.Serialize(ms, tempObj);
                }
            
                return ms.ToArray();
            }
        }
    }
timnavigate
  • 741
  • 4
  • 12
  • 23
Mido
  • 341
  • 2
  • 15

0 Answers0