Burst Compile Error while reading from SharedComponentDataArray

Reading from SharedComponentDataArray in a burst compiled IJobParallelFor job trigger following error in editor:
"
C:\Users\TF\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.entities@0.0.12-preview.8\Unity.Entities\Iterators\SharedComponentDataArray.cs(38,13): error: Unable to get field because it is a class type

While processing function !0 Unity.Entities.SharedComponentDataArray1::get_Item(System.Int32)`

While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct1<LOTE.Utility.OffsetSharedData1<LOTE.Data.EntityFaction>>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)

Compiler exception: System.InvalidOperationException: Unable to get field because it is a class type
at Burst.Compiler.IL.ILVisitor.Ldfld (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0001b] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0043a] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVerifier.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00000] in <19eeae212983462598cc0ee7b1756077>:0
"

"
C:\Users\TF\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.entities@0.0.12-preview.8\Unity.Entities\SharedComponentManager.cs(190,9): error: The given key was not present in the dictionary.

While processing function T Unity.Entities.SharedComponentDataManager::GetSharedComponentData<T>(System.Int32)

While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct1<LOTE.Utility.OffsetSharedData1<LOTE.Data.EntityFaction>>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)

Compiler exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x0001e] in :0
at Burst.Compiler.IL.ILVisitor.GetStructLayout (Mono.Cecil.TypeReference structType) [0x0001e] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.Ldfld (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0003b] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0043a] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVerifier.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00000] in <19eeae212983462598cc0ee7b1756077>:0
"

"
C:\Users\TF\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.entities@0.0.12-preview.8\Unity.Entities\SharedComponentManager.cs(190,9): error: Error while compiling parameter this for function !0 System.Collections.Generic.List1<System.Object>::get_Item(System.Int32): The managed class type System.Collections.Generic.List1<System.Object> is not supported by burst

While processing function T Unity.Entities.SharedComponentDataManager::GetSharedComponentData<T>(System.Int32)

While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct1<LOTE.Utility.OffsetSharedData1<LOTE.Data.EntityFaction>>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)

Compiler exception: System.NotSupportedException: The managed class type System.Collections.Generic.List1<System.Object> is not supported by burst at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference typeReference, Burst.Compiler.IL.Syntax.GenericContext genericContext, System.Collections.Generic.HashSet1[T] structBeingVisited, Burst.Compiler.IL.Syntax.TypeUsage typeUsage) [0x002bc] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference typeReference, Burst.Compiler.IL.Syntax.GenericContext genericContext, System.Collections.Generic.HashSet`1[T] structBeingVisited, Burst.Compiler.IL.Syntax.TypeUsage typeUsage) [0x0023a] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference typeReference, Burst.Compiler.IL.Syntax.GenericContext genericContext, Burst.Compiler.IL.Syntax.TypeUsage typeUsage) [0x00006] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.CompileFunctionArgument (Burst.Backend.FunctionBuilder functionBuilder, Burst.Compiler.IL.Syntax.ILFunction function, Burst.Compiler.IL.Syntax.ParameterBinding paramBinding) [0x00038] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVerifier.CompileFunctionArgument (Burst.Backend.FunctionBuilder functionBuilder, Burst.Compiler.IL.Syntax.ILFunction function, Burst.Compiler.IL.Syntax.ParameterBinding paramBinding) [0x00000] in <19eeae212983462598cc0ee7b1756077>:0
"

"
C:\Users\TF\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.entities@0.0.12-preview.8\Unity.Entities\SharedComponentManager.cs(190,9): error: The opcode instruction IL_0021: unbox.any T args(IL_001c) is not supported by burst

While processing function T Unity.Entities.SharedComponentDataManager::GetSharedComponentData<T>(System.Int32)

While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct1<LOTE.Utility.OffsetSharedData1<LOTE.Data.EntityFaction>>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)

Compiler exception: System.NotSupportedException: The opcode instruction IL_0021: unbox.any T args(IL_001c) is not supported by burst
at Burst.Compiler.IL.ILVisitor.NotSupported (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0016b] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00498] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVerifier.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00000] in <19eeae212983462598cc0ee7b1756077>:0
"

(0,0): error: The managed class type System.Collections.Generic.List1<System.Object>` is not supported by burst

While processing function !0 System.Collections.Generic.List1<System.Object>::get_Item(System.Int32)`

While compiling job: System.Void Unity.Jobs.IJobParallelForExtensions/ParallelForJobStruct1<LOTE.Utility.OffsetSharedData1<LOTE.Data.EntityFaction>>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)

Compiler exception: System.NotSupportedException: The managed class type System.Collections.Generic.List1<System.Object> is not supported by burst at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference typeReference, Burst.Compiler.IL.Syntax.GenericContext genericContext, System.Collections.Generic.HashSet1[T] structBeingVisited, Burst.Compiler.IL.Syntax.TypeUsage typeUsage) [0x002bc] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference typeReference, Burst.Compiler.IL.Syntax.GenericContext genericContext, Burst.Compiler.IL.Syntax.TypeUsage typeUsage) [0x00006] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.CompileType (Mono.Cecil.TypeReference resolveGenerics, Burst.Compiler.IL.Syntax.TypeUsage usage) [0x00014] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.GetStructLayout (Mono.Cecil.TypeReference structType) [0x00015] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.Ldfld (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0003b] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVisitor.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x0043a] in <19eeae212983462598cc0ee7b1756077>:0
at Burst.Compiler.IL.ILVerifier.CompileInternal (Burst.Compiler.IL.Syntax.ILInstruction inst) [0x00000] in <19eeae212983462598cc0ee7b1756077>:0

"

Note that none of them show up when not using burst compile.

Unable to get field because it is a class type

You can’t use classes in jobs and you seem to be using a List

The managed class type `System.Collections.Generic.List`1<System.Object>` is not supported by burst

The isharedcomponent struct simply contain an enum, so i suspect the list is related to sharecomponentdataarray. Since there is no error when burst compile is not on.

can you post your job?

    public struct CopySharedData<T> : IJobParallelFor where T : struct, ISharedComponentData
    {
        [ReadOnly] public SharedComponentDataArray<T> Source;
        [WriteOnly] public NativeArray<T> Results;


        public void Execute(int index)
        {
            Results[index] = Source[index];
        }
    }

You have to disable the parallel for write restriction

It has nothing to do with parallel for write restriction, I am not doing anything funny with index. And it works fine without burst.

sorry - did not read this properly. You already narrowed it to the reading part and I do not know the reason…

SharedComponentData are managed data at the moment. They can’t be used from burst compiled jobs.