Dear ladies and sirs.
Observe the following sample code:
struct DDD
{
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 512, ArraySubType = UnmanagedType.I1)]
byte[] x;
}
struct BBB
{
DDD x;
}
struct CCC
{
DDD x;
ulong y;
ulong z;
}
[StructLayout(LayoutKind.Explicit)]
struct AAA
{
[FieldOffsetAttribute(0)]
BBB a;
[FieldOffsetAttribute(0)]
CCC b;
}
Unfortunately, AAA
cannot be loaded, trying to execute new AAA()
fails with System.TypeLoadException: Could not load type 'AAA' from assembly 'Shunra.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=807fc02bc4ce69db' because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field.
How do one deal with it?
Thanks.
EDIT:
BTW, This is a stripped down version of MINIDUMP_CALLBACK_INPUT struct interop created by PInvokeTool (the original struct is defined in DbgHelp.h)