I am having "Incorrectly aligned or overlapped by non-object field" error with the following code.
public struct TypeA
{
public string A1;
public string A2;
}
public struct TypeB
{
public string B1,
public string B2;
}
I implemented union by using System.Runtime.InteropServices with LayoutKind.Explicit
[StructLayout(LayoutKind.Explicit)]
public struct TypeAorB
{
[FieldOffset(0)]
public TypeA aa;
[FieldOffset(0)]
public TypeB bb;
}
I think the issue comes from string in the struct. How do I overcome this problem?