error DC0001: Entities.ForEach Lambda expression uses field 'commandBuffer in a reference type'. Either assign the field to a local outside of the lambda expression and use that instead, or use .WithoutBurst() and .Run()

I have a shader for dissolve effect and end of it need to destroy obj. How can ı assign variable for newly added data component.

My error:

error Assets\Scripts\Systems\DissolveController.cs(33,9): error DC0001: Entities.ForEach Lambda expression uses field 'commandBuffer in a reference type'. Either assign the field to a local outside of the lambda expression and use that instead, or use .WithoutBurst() and .Run()

Here is my code:

using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Physics;
using Unity.Transforms;
using Unity.Collections;
using UnityEngine;
using Unity.Rendering;

[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
public class DissolveController : SystemBase
{
    EndSimulationEntityCommandBufferSystem _commandBufferSystem;
    public EntityCommandBuffer commandBuffer;

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

    protected override void OnUpdate()
    {
        float deltaTime = Time.DeltaTime;

        commandBuffer = _commandBufferSystem.CreateCommandBuffer();
        Entities.ForEach((ref Entity entity,ref DissolveValue dissolveValue, ref DissolveData data) =>
            {
                if (data.dissolveValue < 1)
                {
                    data.dissolveValue += data.speed;
                    dissolveValue.Value = data.dissolveValue;
                }
                else
                {
                    commandBuffer.DestroyEntity(entity);
                }
            })
            .Run();
    }
}

error DC0001: Entities.ForEach Lambda expression uses field ‘commandBuffer in a reference type’. Either assign the field to a local outside of the lambda expression and use that instead, or use .WithoutBurst() and .Run()

Error says it all: You are referencing an class field ( DissolveController::commandBuffer) and this is not allowed. Also - a command buffer to work must be re-created every update, so 0 reasons to hoard it like that.

using Unity.Entities;
using Unity.Jobs;

[UpdateInGroup( typeof(FixedStepSimulationSystemGroup) )]
public class DissolveController : SystemBase
{
	EndSimulationEntityCommandBufferSystem _commandBufferSystem;
	protected override void OnCreate()
	{
		_commandBufferSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
	}
	protected override void OnUpdate()
	{
		float deltaTime = Time.DeltaTime;

		var commandBuffer = _commandBufferSystem.CreateCommandBuffer().AsParallelWriter();
		Entities
			.WithName("give_me_a_name_job")// "_job" postfix is mandatory (also no spaces), name will help with debugging later on
			.ForEach( ( ref DissolveValue dissolveValue , ref DissolveData data , in int entityInQueryIndex , in Entity entity ) =>
			{
				if( data.dissolveValue<1 )
				{
					data.dissolveValue += data.speed;
					dissolveValue.Value = data.dissolveValue;
				}
				else
				{
					commandBuffer.DestroyEntity( entityInQueryIndex , entity );
				}
			})
			.WithBurst()
			.ScheduleParallel();
		
		_commandBufferSystem.AddJobHandleForProducer( this.Dependency );
	}
}