F# 为什么Mono.Cecil HelloWorld示例会出现异常而失败?

F# 为什么Mono.Cecil HelloWorld示例会出现异常而失败?,f#,mono.cecil,F#,Mono.cecil,这里出了什么问题?我猜问题是由以下几行引起的: Unhandled Exception: System.TypeLoadException: Could not load type 'HelloWorld.Program' from assembly 'Hello on=1.0.0.0, Culture=neutral, PublicKeyToken=null' because the method 'Main' has no implementation (no RVA). 在C#中,这会将

这里出了什么问题?

我猜问题是由以下几行引起的:

Unhandled Exception: System.TypeLoadException: Could not load type 'HelloWorld.Program' from assembly 'Hello
on=1.0.0.0, Culture=neutral, PublicKeyToken=null' because the method 'Main' has no implementation (no RVA).
在C#中,这会将
Main
方法的IL处理器分配给
IL
变量,但在F#中,这只是一个相等性测试,它会导致
false
,因此要为
Main
方法生成的IL代码会添加到构造函数的先前
IL
处理器中

您应该能够使用变量阴影修复此问题:

// create the method body
il = mainMethod.Body.GetILProcessor()

是的,就是这样。虽然与其使用let语句,不如将其绑定到lambda,否则会出现重复变量错误。此外,我之前已经注意到,出于某种原因,F#在等式测试中没有给我通常的非单位警告,但我没有想到再次检查相同的错误。谢谢。@MarkoGrdinic您不会在脚本的顶层得到平等测试警告(您可能需要编写多个表达式并逐个运行它们)。如果您的代码在函数中(无论如何,这是一个更好的结构),您将得到这些
// create the method body
il = mainMethod.Body.GetILProcessor()
// create the method body
let il = mainMethod.Body.GetILProcessor()