not sure why I am getting all this, thanks anyway.
either this struct has strict requirements or it has not.
if it has, I doubt it should hold both public byte dataSenderBytes; and public string dataSender; // 12
same for public byte dataMessageBytes; and public string dataMessage; // 24
if it has not, don't see why it should need a Pack=1 attribute
your problem is with string handling.
in the native world (C, C++) strings consist of 8-bit characters (or 16-bit wide characters) and they end on the first ASCII NULL character (byte value zero), which means the NULL character itself cannot be embedded in a string.
in the managed world strings can contain any character you choose; if you give 12 bytes (dataSenderBytes) to ASCII.GetString() it probably returns a 12-character string of which several could be NULL (or \0).
So I suggest you get the meaningful length of those strings somehow from the byte or from the native world, then use ASCIIEncoding.GetString(Byte, 0, length)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets