F # System.TypeLoadException

using this code

module ObjectRe = type BM = A | N type Object = { Name: string Pattern: BM array } let patterns = [|{Name = "Pro"; Pattern = [|A;N;N;A|]} |] 

I always get this error message

 System.TypeLoadException: Could not load type 'FSI_0007+ObjectRe+Object[]' 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, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in <94fd79a3b7144c54b4cb162b50fc7761>:0 Stopped due to error 

Does anyone have an idea? I am using Visual Studio Code on Mac.

thanks

+5
source share
1 answer

I can also reproduce this on macOS 10.11, mono 4.6.

Minimum Playback:

 module X = type Y = Y let l = [| Y |] 

Workaround :

 module X = type Y = Y let g = List.toArray [ Y ] 

So, in your case, replace both internal and external declarations [| |] [| |] .

Why does this only happen in VS Code / fsharpi, but not in Xamarin?

If you activate the activity monitor, you will see that VS Code / fsharpi uses /Library/Frameworks/Mono.framework/Versions/4.6.0/lib/mono/4.5/fsi.exe , but Xamarin Studio uses FCS Xamarin Studio.app/Contents/Resources/lib/monodevelop/AddIns/BackendBindings/MonoDevelop.FSharpInteractive.Service.exe You can also check the version on the first message from the interactive one ( F# Interactive for F# 4.1 , this may be different).

Finally, I believe this is a bug in mono + dynamic builds, caused by the code emitted by fsi . Compiling this code in exe works fine on all platforms (and if you check that the generated IL looks pretty normal).

+7
source

All Articles