We’re constructing a buffer of bytes to send out on a .Net Socket Send() method to some factory equipment so the byte order matters. But I’ve noticed that even when I use “[StructLayout(LayoutKind.Sequential,” the Visual Studio 2010 debugger shows a different sequence than I specify. For example,
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class K_NEWFILEGET_START
{
public K_HEADER Header = new K_HEADER();
[System.Runtime.InteropServices.MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] fileName = new byte[32];
public globals.INT2_Type crc = new globals.INT2_Type();
}
then I do a
K_NEWFILEGET_START msg = new K_NEWFILEGET_START();
In the debugger it shows . . .
- msg {xxxxx.yyy.K_NEWFILEGET_START}
+ crc {xxxxx.globals.INT2_Type}
+ fileName {byte[32]}
+ Header {xxxxx.yyy.K_HEADER}
(proprietary stuff xxx’ed out) In this example it’s in the reverse order but I have other examples where the displayed order in the debugger is scrambled in different ways.
If I take it one step further and examine the actual output on the network, using a network sniffer, it seems to be in the correct order I specified, so the debugger seems to be the problem but I’d like to see it correctly. BTW I do have “show raw structure of objects in variables windows” set in the debugger options.
Thanks in advance!
The debugger is showing you the members in alphabetical order.
That’s usually more convenient when debugging large structures withe a lot of stuff in them.