observer le exemple de code suivant:Comment déclarer une union en C#?
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;
}
Malheureusement, AAA
ne peut pas être chargé, en essayant d'exécuter new AAA()
échoue avec 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.
Comment faire un accord avec elle?
Merci.
EDIT:
BTW, Ceci est une version dépouillée de Interop de MINIDUMP_CALLBACK_INPUT créé par PInvokeTool (struct d'origine est défini dans DbgHelp.h)
Incorrect. On peut avoir deux FieldOffestAttributes avec un décalage de 0. – mark