【发布时间】:2016-02-21 23:39:43
【问题描述】:
所以,我试图让这个简单的测试在 F# 控制台应用程序中运行:
open System.Reflection
open System.ComponentModel.Composition
open System.ComponentModel.Composition.Hosting
[<Export(typeof<int -> string>)>]
let toString(i: int) = i.ToString()
[<EntryPoint>]
let main argv =
use catalog = new AssemblyCatalog(Assembly.GetEntryAssembly())
use container = new CompositionContainer(catalog)
let myFunction = container.GetExportedValue<int -> string>()
let result = myFunction(5)
0
我希望 MEF 能够正确解决该功能,但事实并非如此。 相反,我得到了这个:
未处理的类型异常
'System.ComponentModel.Composition.CompositionContractMismatchException'发生在 System.ComponentModel.Composition.dll补充资料:
Cannot cast the underlying exported value of type 'Program.toString (ContractName="Microsoft.FSharp.Core.FSharpFunc(System.Int32,System.String)")' to type 'Microsoft.FSharp.Core.FSharpFunc``2[System.Int32,System.String]'.
- 我在这里缺少什么?
-
FSharpFunc(System.Int32, System.String)和FSharpFunc``2[System.Int32, System.String]有什么区别? - 通过 MEF 导入/导出 F# 函数的正确方法是什么?
【问题讨论】: