troubleshooting Question

Serialization of an Int16 returning 52bytes????

Avatar of jbutterfieldAtDiamond
jbutterfieldAtDiamond asked on
.NET ProgrammingC#Microsoft Development
7 Comments1 Solution426 ViewsLast Modified:
I am currently trying to serialize a custom class however I am getting a much larger Byte array than i would expect. In an effort to diagnose the issue I replaced my class with an Int16 object. I would expect the oMemStream.ToArray() to return a byte array of length 2. based on the int16 abc having a value of 0x0706. Instead i am recieving a byte array of length 52.

Can anyone explain how and why i am getting so much data, and two how to get the byte array that actually represents the value of this int16 in such a way that i can apply that knowledge to my custom class.

Thank you.
Int16 abc = 0x0706;
            try
            {
                MemoryStream oMemStream = new MemoryStream();
                BinaryFormatter oBinaryFormatter = new BinaryFormatter();
                oBinaryFormatter.Serialize(oMemStream, abc);
                Byte[] oCommMessage = oMemStream.ToArray();
                oMemStream.Close();
                
            }
            catch { MessageBox.Show("Error Seralizing ABxCmdMessage"); }
 
            return msgStatus;
ASKER CERTIFIED SOLUTION
Snarf0001

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros