在可移植类库中使用F#JsonProvider失败
我试图使用JsonProvider,在调用其上的函数时出现以下错误:在可移植类库中使用F#JsonProvider失败,f#,type-providers,f#-data,F#,Type Providers,F# Data,我试图使用JsonProvider,在调用其上的函数时出现以下错误: System.TypeInitializationException was unhandled Message: An unhandled exception of type 'System.TypeInitializationException' occurred in PortableLibrary1.dll Additional information: The type initializer for '<St
System.TypeInitializationException was unhandled
Message: An unhandled exception of type 'System.TypeInitializationException' occurred in PortableLibrary1.dll
Additional information: The type initializer for '<StartupCode$PortableLibrary1>.$PortableLibrary1' threw an exception.
让绑定被编译成静态成员,在.NET中,当静态初始值设定项中出现异常时,真正的异常被伪装 如果通过更改为
let result()=doc.GeneratedAt
和printfn“%a”(Pinit.result())
将其转换为函数调用,您将得到真正的异常:
Only web locations are supported
便携式配置文件不支持访问文件系统。因此,在PCL中,您可以拥有web URL,也可以从嵌入式资源手动加载。有关示例,请参见此处:。或者,您可以在console项目中使用file.ReadAllText
加载该文件,并将其传递给PCL
这是一个PortableProfile(遗留)项目,即Profile47(和FSharp.core2.3.6.0)。然后,我还测试了一个便携式概要文件项目,即概要文件7(和FSharp.Core 3.3),并注意到它工作不正常,而是给出了这个异常
Method not found: 'FSharp.Data.Runtime.JsonValueOptionAndPath FSharp.Data.Runtime.JsonRuntime.TryGetPropertyUnpackedWithPath(FSharp.Data.Runtime.IJsonDocument, System.String)'.
我创建了一个github问题来跟踪它:Pinit.result是什么??我已将我的问题更新为Pinit.result。这只是JsonProvider分配的结果。在这种情况下,它恰好是一个System.DateTimeThank。我现在已经切换到使用嵌入式资源,但不幸的是我使用的是Profile 7,所以我使用的是您上面提到的方法Not Found exception。
open PortableLibrary1
[<EntryPoint>]
let main argv =
printfn "%A" Pinit.result
0
-- ConsoleApplication --
FSharp.Core = 4.3.1.0
-- PortableClassLibrary --
FSharp.Core = 3.3.1.0
FSharp.Data = NuGet Version: 2.0.0
Only web locations are supported
Method not found: 'FSharp.Data.Runtime.JsonValueOptionAndPath FSharp.Data.Runtime.JsonRuntime.TryGetPropertyUnpackedWithPath(FSharp.Data.Runtime.IJsonDocument, System.String)'.