heroku - 为什么数组中的记录会导致heroku 中的类型初始值设定项错误?

标签 heroku f# typeinitializeexception

我正在将 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 受到此影响,并且 bug 讨论中的报告有点矛盾 - 但最新稳定版本的 mono 4.8.0 似乎至少适用于一个人......

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

关于heroku - 为什么数组中的记录会导致heroku 中的类型初始值设定项错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44245358/

相关文章:

docker - Heroku的Docker应用程序在超过40层启动时崩溃

ruby-on-rails - rails : CSRF token not working but setup

asynchronous - 语音识别引擎未关闭 - 无效操作异常

c# - 'Quartz.Impl.StdSchedulerFactory' 的类型初始值设定项抛出异常

heroku - 如何从 Heroku 上运行的应用程序内部以编程方式设置 Heroku 配置变量?

python - heroku:无法检测到此应用程序的默认语言

c# - 如何在C#中改进推送数据管道以使其性能与F#相匹配

F# 构造常量分组

c# - 是否有工具或策略可以找出项目需要引用的所有 .dll 和 nuget 包?