ReSharper 2026.1 Help

代码检查:Burst:String.Format(format, ...) 参数类型无效

此检查用于报告在由 Burst 编译器编译的代码中传递给 string.Format() 的不支持的参数类型。

在 Burst 中, string.Format 仅支持有限的一组参数。 如果其中一个格式参数是托管类型,或者甚至是 string ,此检查会发出警告,因为在此情况下 Burst 仅支持值类型参数。 托管对象,如 CultureInfo ,也会触发此警告。

示例

在此示例中,向 string.Format 传递了字符串参数。 在 Burst 编译代码中不支持此操作。

using Unity.Burst; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { public void Execute() { // Reported: String arguments are not supported in string.Format within Burst string.Format("Player: {0}", "Alice"); } }
using Unity.Burst; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { public int score; public void Execute() { // Correct: Use Burst-compatible value types string.Format("Score: {0}", score); } }

快速修复

此检查不提供专用的快速修复。 请通过将不受支持的格式参数替换为 Burst 兼容的值类型,或将格式化操作移出 Burst 编译代码来手动修复。

2026年 5月 8日