为什么数组中的记录会导致 heroku 中的类型初始化错误?

Why does a record in an array cause a type initializer error in heroku?

我正在将 F# 应用程序作为脚本部署到 heroku,但我遇到了非常奇怪的问题。我在下面指出的情况下收到以下错误,但在其他情况下没有:

System.TypeLoadException: Could not load type 'FSI_0007+Test[]' from assembly 'FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x410a5830 + 0x000b7> in :0

错误案例:

type Test = { Test: string }
printfn "%A" [|{Test = "test"}|]  <--- error here

工作案例:

printfn "%A" [|"test"|]

type Test = { Test: string }
printfn "%A" {Test = "test"}

printfn "%A" [{Test = "test"}]

看来我不能将记录放入数组中,但我可以将任何内置类型放入数组中。另外,我可以将记录放入列表中。记录本身就很好。

为什么记录加数组的组合会出错?

我在这里使用构建包: https://github.com/SuaveIO/mono-script-buildpack

使用 mono-4.4.2.11。

visual studio 中的本地 fsi 不会发生这种情况。

这看起来很像 this bug in mono

我不确定哪个版本的 mono 受此影响,错误讨论中的报告有点矛盾 - 但最新的稳定版本 mono 4.8.0 似乎至少适用于一个人。 ..

另一种解决方法是将您的网站更改为使用 fsproj 以便代码作为可执行文件编译和启动(而不是使用 fsx 文件并通过 F# 交互式运行)——我认为编译后的代码不会受到此错误(或涉及单反射的其他潜在错误)的影响。