【问题标题】:Cannot get F# Chiron Json serializer working on Linux无法让 F# Chiron Json 序列化程序在 Linux 上运行
【发布时间】:2017-01-22 10:54:53
【问题描述】:

我无法让Chiron Json 序列化程序在带有 VS Code 的 Elementary OS 上工作。

在 Windows 上,它在我测试时可以正常工作。如果我没记错的话,在 MacOS 上它也能正常工作。

这是最小的不工作解决方案:

这是脚本文件App.fsx:

#load "paket-files/include-scripts/net46/include.chiron.fsx"

open Chiron

printfn "%A" (Object <| Map.ofList [ "foo", String "bar" ] |> Json.format)

这是paket.dependencies 文件:

source https://www.nuget.org/api/v2
nuget Chiron

必须生成包含脚本。从 IDE 或通过执行 mono ./paket/paket.exe generate-include-scripts

当我运行fsharpi App.fsx 时出现以下错误:

/tmp/test/stdin(0,1): error FS0078: Unable to find the file 'FParsecCS.dll' in any of
 /usr/lib/mono/4.5
 /tmp/test/./packages
 /tmp/test
 /usr/lib/cli/fsharp/
System.TypeInitializationException: The type initializer for 'Escaping' threw an exception.
  at Chiron+Formatting+formatObject@728-1.Invoke (System.Tuple`2[T1,T2] tupledArg) [0x0000f] in <57e2953614a049a0a74503833695e257>:0 
  at Microsoft.FSharp.Core.FSharpFunc`2[T,TResult].InvokeFast[V] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] func, T arg1, TResult arg2) [0x00018] in <566a0818dff9fae1a745038318086a56>:0 
  at Chiron+Formatting+join@667-2[a].Invoke (System.Text.StringBuilder b) [0x00029] in <57e2953614a049a0a74503833695e257>:0 
  at Chiron+Formatting+join@666-1[a].Invoke (Microsoft.FSharp.Collections.FSharpList`1[T] values, System.Text.StringBuilder b) [0x00013] in <57e2953614a049a0a74503833695e257>:0 
  at Microsoft.FSharp.Core.OptimizedClosures+Invoke@3252[T2,TResult,T1].Invoke (T2 u) [0x00001] in <566a0818dff9fae1a745038318086a56>:0 
  at Chiron+Formatting+formatObject@726-6.Invoke (System.Text.StringBuilder x) [0x00013] in <57e2953614a049a0a74503833695e257>:0 
  at Chiron+Formatting+formatObject@726-7.Invoke (System.Text.StringBuilder x) [0x00001] in <57e2953614a049a0a74503833695e257>:0 
  at Chiron+Formatting+formatObject@726-8.Invoke (System.Text.StringBuilder x) [0x00001] in <57e2953614a049a0a74503833695e257>:0 
  at Chiron+Formatting+Json.format (Chiron+Json json) [0x00013] in <57e2953614a049a0a74503833695e257>:0 
  at <StartupCode$FSI_0001>.$FSI_0001.main@ () [0x00046] in <6e3acc116b9749ea9b5dc27663d21170>: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 <8f2c484307284b51944a1a13a14c0266>:0 
Stopped due to error

如果你不在 Linux 上,可以使用 docker 重现错误,如下所示:

docker run -it -v $(pwd):/tmp/ttt fsharp/fsharp bin/bash

更新

直接引用程序集也不起作用:

#r "packages/Aether/lib/net35/Aether.dll" 
#r "packages/FParsec/lib/net40-client/FParsecCS.dll"
#r "packages/FParsec/lib/net40-client/FParsec.dll"
#r "packages/Chiron/lib/net40/Chiron.dll" 

open Chiron

printfn "%A" (Object <| Map.ofList [ "foo", String "bar" ] |> Json.format)

【问题讨论】:

  • 也许您可以尝试使用Fleece 看看它是否适用于该环境。如果它有效,你会发现它基本上是同一个项目,虽然两者都基于 Aeson,但 Chiron 似乎从 Fleece 复制了很多代码和想法而没有引用它。
  • Fleece 不是同一个项目。 Chiron 在几年前发布时确实引用了 Fleece。随着 chiron 不断更新,在 Chiron 而不是 Fleece 上 +1。
  • 感谢@Henrik,但我想知道复制项目而不是克隆并贡献回原始项目有什么意义。 PR被拒绝了吗?如果方法相同,为什么要重复努力?
  • 方法不一样。关键是mausch由于私人原因不维护Fleece。
  • 可能是 Elementary(基于较旧的 ubuntu)需要更新的单声道,而不是默认 repo 提供的任何一个?尝试添加 mono repo 并从那里升级。

标签: linux f# mono visual-studio-code


【解决方案1】:

您需要包括:

 #r "packages/FParsec/lib/net40-client/FParsecCS.dll"
 #r "packages/FParsec/lib/net40-client/FParsec.dll"

也是。

你可能遇到过this issue

【讨论】:

  • 嗨@Henrik,感谢您的回答。不幸的是,这并不能解决问题。生成的包含脚本正是这样做的。如果我手动引用程序集(按此顺序Aether.dllFParsecCS.dllFParsec.dllChiron.dll)我会得到同样的错误。
【解决方案2】:

不确定您缺少什么,但使用 fsharp docker 容器我​​能够运行它:

#I "packages/FParsec/lib/net40-client/"
- #I "packages/Aether/lib/net35/"     
- #I "packages/Chiron/lib/net40/";;

--> Added '/root/packages/FParsec/lib/net40-client/' to library include path


--> Added '/root/packages/Aether/lib/net35/' to library include path


--> Added '/root/packages/Chiron/lib/net40/' to library include path

> #r "Chiron.dll";;

--> Referenced '/root/packages/Chiron/lib/net40/Chiron.dll' (file may be locked by F# Interactive process)

> open Chiron
- 
- printfn "%A" (Object <| Map.ofList [ "foo", String "bar" ] |> Json.format);;
Binding session to '/root/packages/FParsec/lib/net40-client/FParsecCS.dll'...
Binding session to '/root/packages/FParsec/lib/net40-client/FParsec.dll'...
"{"foo":"bar"}"

val it : unit = ()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 2021-01-14
    • 2015-01-09
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    相关资源
    最近更新 更多