【发布时间】:2014-03-13 07:26:00
【问题描述】:
我正在尝试使用 JsonProvider,当我在其上调用函数时出现以下错误:
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.
我有一个基本的控制台应用程序如下:
module Pinit =
open FSharp.Data
type JsonT = JsonProvider<"""..\myFile.json""">
let doc = JsonT.Load("""..\nyFile.json""")
let result = doc.GeneratedAt
[<EntryPoint>]
let main argv =
printfn "%A" Pinit.doc.GeneratedAt
0
在 ConsoleApplication 中运行时,一切都按预期工作。 如果我按如下方式创建 F# 可移植类库:
module Pinit =
open FSharp.Data
type JsonT = JsonProvider<"""..\myFile.json""">
let doc = JsonT.Load("""..\nyFile.json""")
let result = doc.GeneratedAt
创建另一个控制台应用程序并引用该可移植类库并调用代码如下:
open PortableLibrary1
[<EntryPoint>]
let main argv =
printfn "%A" Pinit.result
0
当我运行程序时,它会生成上面定义的异常:
我怀疑这是因为 FSharp.Core 的版本,但想知道我是否做错了什么,或者是否有办法让它工作?
版本:
-- ConsoleApplication --
FSharp.Core = 4.3.1.0
-- PortableClassLibrary --
FSharp.Core = 3.3.1.0
FSharp.Data = NuGet Version: 2.0.0
【问题讨论】:
-
Pinit.result是什么? -
我已经通过分配给 Pinit.result 的任务更新了我的问题。这只是 JsonProvider 分配的结果。在这种情况下,它恰好是 System.DateTime
标签: f# type-providers f#-data