我无法使用 fslab 提供的 FSharp.Data csv 提供程序加载 csv 文件,包括示例 adwords.csv 文件。
下面这个错误是什么意思?此外,当我将鼠标悬停在 Visual Studio 编辑器中的代码上时,它提到“字典中不存在给定的键”
问题示例:
#load "packages/FsLab/FsLab.fsx"
open System.IO
open FSharp.Data
"adwords.csv"
|> File.ReadAllLines
let test = CsvProvider<"adwords.csv">.GetSample()
输出:
>
val it : string [] =
[|"Criteria ID,Name,Canonical Name,Parent ID,Country Code,Target Type,Status";
"1000010,Abu Dhabi,"Abu Dhabi,Abu Dhabi,United Arab Emirates",9041082,AE,City,Active";
"1000011,Ajman,"Ajman,Ajman,United Arab Emirates",9047096,AE,City,Active";
"1000012,Al Ain,"Al Ain,Abu Dhabi,United Arab Emirates",9041082,AE,City,Active";
"1000013,Dubai,"Dubai,Dubai,United Arab Emirates",9041083,AE,City,Active";
"2004,Afghanistan,Afghanistan,,AF,Country,Active"|]
>
>System.MethodAccessException: Attempt by method '<StartupCode$FSI_0007>.$FSI_0007.main@()' to access method 'FSharp.Data.Runtime.CsvFile`1<System.__Canon>.Create(System.Func`3<System.Object,System.String[],System.__Canon>,
at <StartupCode$FSI_0007>.$FSI_0007.main@() in C:\test.fsx:line 11
Stopped due to error
我自己的文件遇到了这个问题,所以我从这里获取了这个示例文件:https ://raw.githubusercontent.com/fsharp/FSharp.Data/master/tests/FSharp.Data.Tests/Data/Adwords.csv
调试信息:
- 如果我删除 FSharp.Data 库文件夹(v 2.3.0)并替换为 2.2.5 版本,它可以正常工作,没有错误。
如果我不使用 FsLab.fsx 脚本而是使用
#I "packages/FSharp.Data/lib/net40 #r "FSharp.Data.dll"
然后一切正常。- FsLab.fsx 脚本的路径是正确的,它在我将行发送到 fsi 时运行。
- F# 版本是 14.0.23413.0。
- FSlab下载的FSharp.Data版本为FSharp.Data.2.3.0。
- 我在 .fsx 脚本中没有其他引用。
- 我正在使用 Visual Studio 社区版 14.0.24720.00 更新 1。
- .NET 版本 4.6.01038
- 我现在意识到我没有收到弹出窗口,询问我是否要允许 .dll,就像我以前使用它时那样。