从C#调用Freebase Provider时,FSharp.Data'System.MissingMethodException'

时间:2014-03-24 11:46:46

标签: c# f# freebase f#-data missingmethodexception

嗨我在F#上有这段代码,如果我从F#Interactive Editor测试它,那么isPalindrome和Extract方法都能正常工作:

namespace Portable3
open FSharp
open FSharp.Data
open Microsoft.FSharp.Linq 
open FSharp.Data.FreebaseOperators
open MyTrip.Model.MyTrip
open MyTrip.Model.FreeBase
open System.Runtime
open System.Linq

module math = 
let isPalindrome (str : string) = 
 let rec check(s : int, e : int) =
    if s = e then true
    elif str.[s] <> str.[e] then false
    else check(s + 1, e - 1)
 check(0, str.Length - 1)

 [<AutoOpen>]
 module Extractor =

[<Literal>] 
let FreebaseApiKey = "AIzaSyCO31Ls"
type FreebaseDataWithKey = FreebaseDataProvider<Key=FreebaseApiKey>

let Extract mid = let dataWithKey = FreebaseDataWithKey.GetDataContext()
                  let place = dataWithKey.Commons.Travel.``Travel destinations``.Where( fun x-> x.MachineId = mid) |> Seq.toList                           
                  let result = new Place()   
                  let firstPlace = place.Head
                  result.Name <- firstPlace.Name                      
                  result

我从C#Console应用程序中调用此代码,如下所示:

 class Program
{
    static void Main(string[] args)
    {
        //Works well
        var isPalin = math.isPalindrome("ABsBA");
        //fails
        var res = Extractor.Extract("/m/04jpl");
        Console.WriteLine(res);
        Console.Read();

    }
}

控制台C#项目是.net Framework 4.5.1版本,我也在这个项目上下载了FSharp.Data和FSharp.Core。执行isPalindrome时效果很好但是当我即将执行Extract方法时会出现此错误:

An unhandled exception of type 'System.MissingMethodException' occurred in FsharpConsoleTest.exe

Additional information: Method not found: 'FSharp.Data.Runtime.Freebase.FreebaseDataContext   FSharp.Data.Runtime.Freebase.FreebaseDataContext._Create(System.String, System.String, System.Boolean, System.String, System.Boolean, System.Boolean)'.

知道发生了什么?我在互联网上搜索但没有发现任何相关内容。谢谢!

1 个答案:

答案 0 :(得分:4)

最后的问题是使用带有FSharp.Data的可移植库。我尝试在普通的F#库中使用它,我发现没有问题,我有所有的调试功能,并且没有发生c#与f#集成的错误!