环境:OS-X / Xamarin Studio 6.1 / F#Interactive#F <4.0
已编译:以下版本可以正常编译:
type Movie = {
Name : string
Year: int
}
[<EntryPoint>]
let main argv =
let movies = [
{ Name = "Bad Boys"; Year = 1995 }
]
let json = Newtonsoft.Json.JsonConvert.SerializeObject(movies)
System.Console.WriteLine json
System.Console.ReadKey() |> ignore
0 // return an integer exit code
互动:在交互模式下Newtonsoft.Json&#39; JsonConvert.SerializeObject失败
type Movie = {
Name : string
Year: int
}
let movies = [
{ Name = "Bad Boys"; Year = 1995 }
]
let json = Newtonsoft.Json.JsonConvert.SerializeObject(movies)
输出:
val movies : Movie list = [{Name = "Bad Boys";
Year = 1995;}; {Name = "Bad Boys 2";
Year = 2003;}]
System.BadImageFormatException: Method has zero rva
File name: 'System.Net.Http.Formatting'
at <StartupCode$FSI_0015>.$FSI_0015.main@ () [0x00006] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in <filename unknown>:0
[MVID] 7747cf446af449e194e4b4e70d85e773 2
[MVID] eddc6e27796e462ba5a0f4fbcf15e179 0
我缺少一些设置或者Newtonsoft.Json无法在F#的交互模式下工作。
注意:我正在使用Xamarin Studio自动将所有引用添加到交互式会话中(其中152个)
使用Xamarin Studio:
其中包括:
--> Referenced '/Users/sushi/code/sushi/GeneticGraphDatabase/packages/Newtonsoft.Json.9.0.1/lib/net45/Newtonsoft.Json.dll' (file may be locked by F# Interactive process)
JsonConvert.SerializeObject产生:
System.BadImageFormatException: Method has zero rva
手动参考&#39;使用相同的装配路径:
#r "/Users/sushi/code/sushi/GeneticGraphDatabase/packages/Newtonsoft.Json.9.0.1/lib/net45/Newtonsoft.Json.dll";;
--> Referenced '/Users/sushi/code/sushi/GeneticGraphDatabase/packages/Newtonsoft.Json.9.0.1/lib/net45/Newtonsoft.Json.dll' (file may be locked by F# Interactive process)
按预期工作:
val json : string = "[{"Name":"Bad Boys","Year":1995}]"
答案 0 :(得分:1)
使用Xamarin Studio在使用菜单项时使用的相同程序集路径,手动引用wstart
&#39; :Json.Net
"Edit / Send references to F# Interactive"
按预期工作:
#r "/Users/sushi/code/sushi/GeneticGraphDatabase/packages/Newtonsoft.Json.9.0.1/lib/net45/Newtonsoft.Json.dll";;
--> Referenced '/Users/sushi/code/sushi/GeneticGraphDatabase/packages/Newtonsoft.Json.9.0.1/lib/net45/Newtonsoft.Json.dll' (file may be locked by F# Interactive process)
Bugzilla: https://bugzilla.xamarin.com/show_bug.cgi?id=43307