[BUG] Error while post processing the assembly - 0.3.0-preview.4

After upgrading from 0.1.1 to 0.3.0-preview.4 and converting my old systems, I’m seeing this error:

while using this code:

internal abstract class AbstractRemoveTagJobSystem<TData, TBuffer> : JobComponentSystem
    where TData : struct, IComponentData where TBuffer : EntityCommandBufferSystem
{
    private TBuffer m_CommandBuffer;

    protected override void OnCreate()
    {
        m_CommandBuffer = World.GetOrCreateSystem<TBuffer>();
    }

    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var commandBuffer = m_CommandBuffer.CreateCommandBuffer().ToConcurrent();

        inputDeps = Entities
            .WithAll<TData>()
            .ForEach((Entity entity, int entityInQueryIndex) =>
            {
                commandBuffer.RemoveComponent<TData>(entityInQueryIndex, entity);
            })
            .Schedule(inputDeps);

        m_CommandBuffer.AddJobHandleForProducer(inputDeps);

        return inputDeps;
    }
}

If I comment out the WithAll and the RemoveComponent, the compilation exception no longer occurs.

It is the same whether or not the class is used by a concrete implementation.

I’m also seeing a similiar error:

while using this code:

internal class BulletCollisionSystem : JobComponentSystem
{
    private EntityCommandBufferSystem m_CommandBufferSystem;

    protected override void OnCreate()
    {
        m_CommandBufferSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
    }

    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var commandBuffer = m_CommandBufferSystem.CreateCommandBuffer();

        Entities
            .WithAll<IsBulletTag>()
            .ForEach((Entity entity, DynamicBuffer<NewCollisionElementData> collisionBuffer) =>
            {
                for (int i = 0; i < collisionBuffer.Length; i++)
                {
                    var collisionEntity = collisionBuffer[i].Entity;

                    if (EntityManager.HasComponent<IsTerrainTag>(collisionEntity))
                    {
                        DestroyUtility.MarkForDestroy(entity, commandBuffer);
                        continue;
                    }
                }
            })
            .WithoutBurst()
            .Run();

        return inputDeps;
    }
}

The error disappears if DestroyUtility.MarkForDestroy() is removed.
Note that this occurs even if DestroyUtility.MarkForDestroy() is an empty function.

Furthermore (this is fun):

    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var commandBuffer = m_CommandBufferSystem.CreateCommandBuffer();
        var terrainCDFE = GetComponentDataFromEntity<IsTerrainTag>(true);

        Entities
            .WithAll<IsBulletTag>()
            .WithReadOnly(terrainCDFE)
            .ForEach((Entity entity, DynamicBuffer<NewCollisionElementData> collisionBuffer) =>
            {
                var array = collisionBuffer.ToNativeArray(Allocator.Temp);
                for (int i = 0; i < array.Length; i++)
                {
                    //if (terrainCDFE.Exists(array[i].Entity))
                    if (EntityManager.HasComponent<IsTerrainTag>(array[i].Entity))
                    {
                        //DestroyUtility.MarkForDestroy(entity, commandBuffer);
                        continue;
                    }
                }
            })
            .WithoutBurst()
            .Run();

        return inputDeps;
    }

This code compiles, but using terrainCDFE instead of EntityManager causes the same exception as above.

I get this too, not sure if its 100% the same issue, as mine started when I introduced assembly definitions to my project

My workaround is to go to: Unity.Entities.CodeGen.CecilExtentionsMethods, Line 142 and change it to

var baseTypeRef = arg?.BaseType;

The added null check caused that method to return false and whatever magic was calling it was happy