从C#调用Freebase Provider时FSharp.Data'System.MissingMethodException' [英] FSharp.Data 'System.MissingMethodException' when calling Freebase Provider from C#
问题描述
我在F#上有这段代码,如果我从F#交互式编辑器对其进行测试,则isPalindrome和Extract方法都可以很好地工作:
Hi I have this piece of code on F#, if I test it from the F# Interactive Editor both isPalindrome and Extract methods work well:
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#控制台应用程序调用此代码,如下所示:
And I call this code from a C# Console app like this:
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方法时,会出现此错误:
The console C# project is .net Framework 4.5.1 version, I downloaded the FSharp.Data and FSharp.Core on this project also. When executing isPalindrome works well but when I'm about to execute the Extract method this error appears:
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)'.
有什么想法吗?我在互联网上搜索,但没有发现任何相关信息.谢谢!
Any idea on what's happening? I searched on internet but didn't found anything relevant. Thanks!
推荐答案
最后,问题是使用带有FSharp.Data的可移植库.我尝试在普通的F#库中使用它,但没有发现任何问题,我具有所有调试功能,并且没有发生c#与f#集成的错误!
The problem at the end was using a portable library with FSharp.Data. I tried using it in a normal F# library and I found no problems, I had all the debuggin capabilities, and no errors from c# integration with f# are happening!
这篇关于从C#调用Freebase Provider时FSharp.Data'System.MissingMethodException'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!