Error: it contains an object field at offset 75 that is incorrectly aligned

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aannn
    New Member
    • Sep 2014
    • 4

    Error: it contains an object field at offset 75 that is incorrectly aligned

    Error as like this-->object field at offset 75 that is incorrectly aligned or overlapped by a non-object field. But here size constant is 3 so I think after 72 offset will be 75..If I change the offset to 76 it will works fine. I think reason is that size of int is 4. After changing that code will be like this.
    Code:
    [FieldOffset(72)]
                [MarshalAs(UnmanagedType.ByValArray,SizeConst= 3)]
                public int[] DC;
    
                [FieldOffset(76)]
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
                public float[] WIN;
    
    
                [FieldOffset(84)]
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
                public byte[] name;
    
                [FieldOffset(104)]
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
                public byte[] SET;
    
                [FieldOffset(107)]
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
                public byte[] ID;
    But at that time I got the error as object field at offset 107 that is incorrectly aligned or overlapped by a non-object field..Can anyone tell me what is the main reason behind this..

    Thanks..
Working...