Using F# JsonProvider within a portable class library fails

断了今生、忘了曾经 提交于 2019-12-05 20:11:40

let bindings are compiled into static members, and in .NET when you have an exception in a static initializer the real exception is masqueraded.

If you turn that into a function call by changing to let result() = doc.GeneratedAt and printfn "%A" (Pinit.result()) you'll get the real exception:

Only web locations are supported

Portable profiles don't support accessing the file system. So inside the PCL you can either have web urls or load manually from an embedded resource. See here for an example: https://github.com/ovatsus/Apps/blob/master/Trains/Stations.fs#L65. Or you can load the file with File.ReadAllText in the console project and pass it to the PCL.

This was with a Portable Profile (Legacy) project, which is Profile 47 (and FSharp.Core 2.3.6.0). I then also tested with a Portable Profile project, which is Profile 7 (and FSharp.Core 3.3), and noticed it's not working correctly, it's giving this exception instead

Method not found: 'FSharp.Data.Runtime.JsonValueOptionAndPath FSharp.Data.Runtime.JsonRuntime.TryGetPropertyUnpackedWithPath(FSharp.Data.Runtime.IJsonDocument, System.String)'.

I created a github issue to track that: https://github.com/fsharp/FSharp.Data/issues/521

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!