Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CsvProvider - Error: Attempted to access an element as a type incompatible with the array. #934

Closed
petarvucetin opened this issue Apr 30, 2016 · 1 comment

Comments

@petarvucetin
Copy link

I have a very simple file that is failing to load. The only way to make it work is to add another column.

val it : CsvProvider<...> =
FSharp.Data.Runtime.CsvFile1[System.Tuple1[System.String]]
{Headers = Some [|"Tag"|];
NumberOfColumns = 1;
Quote = '"';
Rows = Error: Attempted to access an element as a type incompatible with the array.;
Separators = ",";}

dummy.zip

@tpetricek
Copy link
Member

I tried to load the file using CsvProvider and did not get any error. Here is what I tried (in a script file):

#r "packages/FSharp.Data/lib/net40/FSharp.Data.dll"
open FSharp.Data

type C = CsvProvider<"C:/temp/dummy.csv">
for r in C.GetSample().Rows do
  printfn "%s" r.Tag

Could you share your F# code? Perhaps I'm using it differently than you are...

One possible reason for the error that I've seen before is when you use relative path as an argument to the CSV type provider - this may sometimes confuse F# Interactive (the editor thinks it is fine, but F# Interactive thinks it is in another folder and fails to find the file when running the type provider).

One fix for this is to use __SOURCE_DIRECTORY__ like this:

let [<Literal>] Dummy = __SOURCE_DIRECTORY__ + "/dummy.csv"
type C = CsvProvider<Dummy>

This way, the path passed to the CSV provider is a full path and it is more robust.

@ovatsus ovatsus closed this as completed May 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants