Why is writing to an array causing a type initializer error in heroku?
I am deploying an F # app in heroku as a script and I am having very strange problems. I get the following error in the following cases, but not in others:
System.TypeLoadException: Failed to load type "FSI_0007 + Test []" from assembly 'FSI-ASSEMBLY, Version = 0.0.0.0, Culture = neutral, PublicKeyToken = null. at (based wrapper) 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 [] options, System.Globalization.CultureInfo culture) <0x410a5830 + 0x000b7> in: 0
Error case:
type Test = { Test: string }
printfn "%A" [|{Test = "test"}|] <--- error here
Working cases:
printfn "%A" [|"test"|]
type Test = { Test: string }
printfn "%A" {Test = "test"}
printfn "%A" [{Test = "test"}]
So, it seems that I cannot put records into arrays, but I can put any built-in types into arrays. Also, I can put entries in lists. And the recordings themselves are good.
Why does the combination of records and arrays cause errors?
I am using buildpack here: https://github.com/SuaveIO/mono-script-buildpack
which uses mono-4.4.2.11.
This does not happen with local fsi in visual studio.
source to share
This is very similar to this error in mono .
I'm not entirely sure which versions of mono were affected by this, and the reports in the bug discussion are a bit conflicting - but the latest stable mono 4.8.0 seems to work for at least one person ...
Another workaround would be to change your site to use fsproj
so that the code compiles and runs as an executable file (instead of using the file fsx
with runs through F # interactive) - I think the compiled code does not suffer from this error (or other possible errors related with Mono Reflection).
source to share