JetBrains Rider 2026.1 Help

代码检查:Burst:变量解析为 System.String,这可能会导致在 Burst 编译的调用堆栈中出现无效的托管方法调用

此检查会报告在 Burst 编译器 编译的代码中解析为 System.String 的本地 var 声明。

Burst 不支持在局部变量中安全地使用常规托管字符串。 当类型推断将本地变量转换为 string 并在 [BurstCompile] 方法或作业中使用时,会触发此检查。

示例

在此示例中, var text 声明被推断为 string。 快速修复会自动将声明转换为显式的 FixedString... 类型。

using Unity.Burst; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { public void Execute() { // Reported: Local var inferred as string is not supported in Burst var text = "Hello"; } }
using Unity.Burst; using Unity.Collections; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { public void Execute() { // After fix: Use Burst-compatible FixedString types FixedString32Bytes text = "Hello"; } }

快速修复

快速修复会将声明转换为显式的 FixedString... 类型(例如, FixedString32BytesFixedString64Bytes 等),以保持代码对 Burst 兼容,并避免推断为 string 的局部变量。

2026年 5月 8日