【问题标题】:FSharp.Data 'System.MissingMethodException' when calling Freebase Provider from C#从 C# 调用 Freebase 提供程序时 FSharp.Data 'System.MissingMethodException'
【发布时间】:2016-03-29 20:36:25
【问题描述】:

您好,我在 F# 上有这段代码,如果我从 F# 交互式编辑器中对其进行测试,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# 控制台应用程序中调用此代码,如下所示:

 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)'.

知道发生了什么吗?我在互联网上搜索,但没有找到任何相关的东西。谢谢!

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      相关资源
      最近更新 更多