使用英语阅读

通过


IL2059:将无法识别的值传递给了“System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor”的 type 参数

原因

将一个无法识别的值传递给了 RuntimeHelpers.RunClassConstructor(RuntimeTypeHandle)type 参数。

规则说明

如果传递给 RunClassConstructor(RuntimeTypeHandle) 的类型不是静态已知的,则剪裁器无法保证目标静态构造函数的可用性。

示例

void TestMethod(Type type)
{
    // IL2059 Trim analysis: Unrecognized value passed to the parameter 'type' of method 'System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(RuntimeTypeHandle type)'.
    // It's not possible to guarantee the availability of the target static constructor.
    RuntimeHelpers.RunClassConstructor(type.TypeHandle);
}