G
Guest
To all,
I’m trying to make a union of an 8 byte array with a set of header values in
order to facilitate the concatenation of the header and byte data into a
packet for transmission, but the structure that I’ve created triggers the
following exception when I try to instantiate it:
System.TypeLoadException was unhandled
Could not load type ‘PacketHeaderStruct’ ... because it contains an
object field at offset 0 that is incorrectly aligned or overlapped by
a non-object field.
The structure:
Const HDR_SIZE as Integer = 8
<StructLayout(LayoutKind.Explicit)> _
Private Structure PacketHeaderStruct
<FieldOffset(0), VBFixedArray(HDR_SIZE-1)> Public hdrBytes() as Byte
<FieldOffset(0)> Public dataType as Short
<FieldOffset(2)> Public version as Byte
<FieldOffset(3)> Public location as Byte
<FieldOffset(4)> Public sequenceNumber as Byte
‘I don’t know if these 3 declarations are necessary…
‘
<FieldOffset(5)> Public reserved1 as Byte
<FieldOffset(6)> Public reserved2 as Byte
<FieldOffset(7)> Public reserved3 as Byte
Public Sub Initialize()
ReDim hdrBytes(HDR_SIZE-1)
End Sub
End Structure
The method that triggers the exception:
Public Function MakePacket( byVal dType as Short, _
byVal version as Byte, byVal location as Byte, _
byRef dataIn() as Byte ) as Byte()
Dim hdr as New PacketHeaderStruct
hdr.Initialize()
hdr.version = version
hdr.location = location
I’m trying to make a union of an 8 byte array with a set of header values in
order to facilitate the concatenation of the header and byte data into a
packet for transmission, but the structure that I’ve created triggers the
following exception when I try to instantiate it:
System.TypeLoadException was unhandled
Could not load type ‘PacketHeaderStruct’ ... because it contains an
object field at offset 0 that is incorrectly aligned or overlapped by
a non-object field.
The structure:
Const HDR_SIZE as Integer = 8
<StructLayout(LayoutKind.Explicit)> _
Private Structure PacketHeaderStruct
<FieldOffset(0), VBFixedArray(HDR_SIZE-1)> Public hdrBytes() as Byte
<FieldOffset(0)> Public dataType as Short
<FieldOffset(2)> Public version as Byte
<FieldOffset(3)> Public location as Byte
<FieldOffset(4)> Public sequenceNumber as Byte
‘I don’t know if these 3 declarations are necessary…
‘
<FieldOffset(5)> Public reserved1 as Byte
<FieldOffset(6)> Public reserved2 as Byte
<FieldOffset(7)> Public reserved3 as Byte
Public Sub Initialize()
ReDim hdrBytes(HDR_SIZE-1)
End Sub
End Structure
The method that triggers the exception:
Public Function MakePacket( byVal dType as Short, _
byVal version as Byte, byVal location as Byte, _
byRef dataIn() as Byte ) as Byte()
Dim hdr as New PacketHeaderStruct
hdr.Initialize()
hdr.version = version
hdr.location = location