First of all the Boolean type is said to have a default marshal type of a four-byte value. So the following code works:
struct A
{
public
It is working as designed.
Here is what is happening:
Take the new int[] { 2, 4 } and lets marshal it into A, B, Broken, and Broken2. The last is the same as Broken, but with fields' order reversed (first b, then a).
If we marshal the ints into these structures we get the following values in memory:
So what is happening is the following:
So for A, the first int gets converted to 1, for B, the second int gets converted to 1, for Broken, since B is the last field, its rules apply, and hence the second int gets converted to 1. Similarly for Broken2.