[0.51-p21] NRE during EntityComponentStore.CreateArchetype in release build

For some reason entity archetype creation fails at:

NullReferenceException: Object reference not set to an instance of an object
  at Unity.Entities.EntityComponentStore.CreateArchetype (Unity.Entities.ComponentTypeInArchetype* types, System.Int32 count) [0x00035] in <11558b8573fe4d5b8fc8f89ae6ba62b0>:0
  at Unity.Entities.EntityComponentStore.GetOrCreateArchetype (Unity.Entities.ComponentTypeInArchetype* inTypesSorted, System.Int32 count) [0x00010] in <11558b8573fe4d5b8fc8f89ae6ba62b0>:0
  at Unity.Entities.EntityDataAccess.CreateArchetype (Unity.Entities.ComponentType* types, System.Int32 count) [0x0003f] in <11558b8573fe4d5b8fc8f89ae6ba62b0>:0
  at Unity.Entities.EntityManager.CreateArchetype (Unity.Entities.ComponentType* types, System.Int32 count) [0x0000c] in <11558b8573fe4d5b8fc8f89ae6ba62b0>:0
  at Unity.Entities.EntityManager.CreateArchetype (Unity.Collections.NativeArray`1[T] types) [0x0000e] in <11558b8573fe4d5b8fc8f89ae6ba62b0>:0

I’ve pinned it down to GetTypeInfo (upon ct access NRE is thrown) at EntityComponentStore:

internal Archetype* CreateArchetype(ComponentTypeInArchetype* types, int count)
        {
            AssertArchetypeComponents(types, count);

            var scalarEntityPatchCount = 0;
            var bufferEntityPatchCount = 0;
            var numManagedArrays = 0;
            var numSharedComponents = 0;
            var enableableComponentIndexInArchetype = stackalloc int[count];
            var numEnableableComponents = 0;

            for (var i = 0; i < count; ++i)
            {
                ref readonly var ct = ref GetTypeInfo(types[i].TypeIndex);

                // Here at ct.Category access attempt
                if (ct.Category == TypeManager.TypeCategory.ISharedComponentData)
                {
                    ++numSharedComponents;
                }
                else if (TypeManager.IsManagedComponent(types[i].TypeIndex))
                {
                    ++numManagedArrays;
                }
                else
                {
                    if (ct.BufferCapacity >= 0)
                        bufferEntityPatchCount += ct.EntityOffsetCount;
                    else if (ct.SizeInChunk > 0)
                        scalarEntityPatchCount += ct.EntityOffsetCount;
                }

                if (types[i].IsEnableable)
                    enableableComponentIndexInArchetype[numEnableableComponents++] = i;
            }
   ...

This happens only in release build, editor and dev build runs fine. (Windows Standalone)
TypeManager is initialized beforehand, and some EntityArchetypes are successfully created.

I know best option is to move to 1.0.11 testing it there, but it will take ages to do so.
Maybe anyone knows what can be causing this?

Okay, managed to figure out what going on.

So it seems size of the IComponentData is computed in editor only and ignore [potential] changes done during building.
Basically, if you have something like:

public struct SomeComponent : IComponentData {
#if DEBUG
     public bool SomeField;
#endif
}

This will cause some buffer misalignment, and an invalid pointer.
Simply removing the directive fixes the problem. But pinning down offending field across 50+ components wasn’t easy.

I just hope this case is covered in Entities 1.+.