The compiler turns top-level F # functions into methods, so your example will be compiled as:
[Export(FSharpFunc<int,string>)] public string toString(int i) { return i.ToString(); }
This is probably causing the error. You can force the compiler to create a getter property of type FSharpFunc by calling some operation that returns a function - even a simple identification function will not:
let makeFunc f = f [<Export(typeof<int -> string>)>] let toString = makeFunc <| fun (i:int) -> i.ToString()
I have not tested this, but I think it might work. However, in this case, it is probably safer to use a simple interface with one method.
source share