Re: unmanaged structure layout error

Benjamin Schwehn <[email protected]> Wed, 11 Nov 2009 20:23:22 +0000
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <[email protected]>
> 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