Re: unmanaged structure layout error

Mike Andrews <[email protected]> Wed, 11 Nov 2009 14:37:55 -0600
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <[email protected]>
But I thought that's what Pack = 1 was for in the StructLayout attribute, so
that you could do just that.
Are you saying that if it's explicit it must be DWORD aligned?

On Wed, Nov 11, 2009 at 2:23 PM, Benjamin Schwehn <[email protected]> wrote:

>  I'm getting this error message when the system tries to load the type:
>>
>> *Could not load type '_S' from assembly '...' because it contains an
>> object
>> field at offset 134 that is incorrectly aligned or overlapped by a
>> non-object field.*
>>
>
> It's not caused by the string.
> Arrays must be DWORD aligned, so you can't have
>
>
> [FieldOffset(60)]
> [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
> private System.Byte[] _u2;
>
> Instead, you could use
>
> [FieldOffset(64)]
>
> [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
> private System.Byte[] _u2;
>
>
> HTH
> Ben Schwehn
>
>
> ===================================
> View archives and manage your subscription(s) at
> http://peach.ease.lsoft.com/archives
>

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives