F#互动错误?

时间:2010-12-30 13:44:12

标签: f# f#-interactive

我在VS2010中尝试了以下代码:

open System.Security.Cryptography

let rsaTest1 =
    let ecKey = [|0uy..143uy|] // junk data for testing

    let ecKeyMod = ecKey.[8..8+128-1]   
    let ecKeyExp = ecKey.[136..136+8-1]
    let rsa = RSAParameters(Modulus = ecKeyMod, Exponent = ecKeyExp)

    rsa


let rsaTest2 =
    let ecKey = [|0uy..143uy|] // junk data for testing

    let rsa = RSAParameters(Modulus = ecKey.[8..8+128-1], Exponent = ecKey.[136..136+8-1])

    rsa

如果我突出显示所有代码并将其发送到F#Interactive(Alt + Enter),则rsaTest1可以正常工作,但rsaTest2会显示错误消息,

System.NullReferenceException: Object reference not set to an instance of an object.
   at <StartupCode$FSI_0004>.$FSI_0004.main@() in P:\proj\Tachograph\Project\CompuTachTest\CompuTachTest\rsaTest.fsx:line 16

但是,如果我将rsaTest2从值更改为函数并调用它,

let rsaTest2 () =
    let ecKey = [|0uy..143uy|] // junk data for testing
    let rsa = RSAParameters(Modulus = ecKey.[8..8+128-1], Exponent = ecKey.[136..136+8-1])
    rsa

let x = rsaTest2 ()

然后没有错误。 F#bug还是我的错误?

1 个答案:

答案 0 :(得分:5)

这很可能是一个错误 - 如果您使用fsc编译已发布的代码段并运行它,那么您可以使用x64:

Unhandled Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program.
at <StartupCode$test>.$Test.main@()

这适用于x86:

Unhandled Exception: System.InvalidProgramException: JIT Compiler encountered an internal limitation.
at <StartupCode$test>.$Test.main@()

您应该通过Microsoft Connect报告。