ReSharper 2025.3 Help

Code inspection: The 'foreach' construction is not supported

This inspection reports foreach loops inside code compiled by the Burst compiler.

Burst does not support the foreach construction, even when iterating over otherwise Burst-compatible data such as native containers.

Example

In this example, the foreach loop is used to iterate over a NativeArray<int> inside a Burst-compiled job. This is not supported and will be flagged.

using Unity.Burst; using Unity.Collections; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { public NativeArray<int> values; public void Execute() { // Reported: foreach is not supported in Burst foreach (var value in values) { } } }
using Unity.Burst; using Unity.Collections; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { public NativeArray<int> values; public void Execute() { // Correct: Replace foreach with an index-based loop for (var i = 0; i < values.Length; i++) { var value = values[i]; } } }
26 March 2026