I want to have a c-style uion type that has a C # struct type.
For some reason, I get an exception every time I allocate the type that I defined. Here is my own type. The main idea is that I have access to the "pointer" of this structure. Unfortunately, I get a TypeLoadException:
Additional information: Failed to load the type 'ManagedTarget.FngPeriodeParameterType' from the assembly 'ManagedTarget, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null', because it contains an object field with an offset of 0 that is incorrectly aligned or overlapped with a field without an object .
What's wrong?
[StructLayout(LayoutKind.Explicit, Size = 16)] unsafe internal struct FngPeriodeParameterType { [FieldOffset(0)] public Byte[] ByteArray; [FieldOffset(0)] public UInt32 Repetitions; [FieldOffset(4)] public Int16 Amplitude; [FieldOffset(6)] public Int16 Offset; [FieldOffset(8)] public Int16 Gain; [FieldOffset(10)] public UInt16 Selection; [FieldOffset(12)] public UInt32 Step; }
source share