JetBrains Rider 2026.1 Help

代码检查:不支持创建托管类型

此检查会报告 new 表达式在 Burst 编译器编译的代码中创建托管类型的情况。

Burst 目标为高性能受限的 C# 子集,仅支持非托管、兼容 Burst 的数据。 在 Burst 编译的代码中创建如 objectList<T> 、异常或其他引用类型的托管对象不受支持,因为这需要进行托管堆分配和垃圾回收。

示例

在此示例中, new List<int>() 表达式被用于 Burst 编译作业的 执行 方法中。 不支持此操作,会被标记出来。

using System.Collections.Generic; using Unity.Burst; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { public void Execute() { // Reported: Creating managed types is not supported in Burst var values = new List<int>(); } }
using Unity.Burst; using Unity.Collections; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { public NativeArray<int> values; public void Execute() { // Use Burst-compatible value types or native containers var first = values[0]; } }

快速修复

此检查不提供专用快速修复。 请手动修复,移除托管分配并用 Burst 兼容的数据替换,例如实例字段、作业数据或受支持的原生容器。

2026年 5月 8日