Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8169655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:54:50+00:00 2026-06-06T20:54:50+00:00

Recently I attended a tutorial by Keith Battochi on type providers, in which he

  • 0

Recently I attended a tutorial by Keith Battochi on type providers, in which he introduced a variant of the MiniCsv type provider in the MSDN tutorial. Unfortunately, my laptop wasn’t available, so I had to write down the code by hand as well as I could. I believe I’ve recreated the type provider, but I’m getting

error FS3033: The type provider 'CsvFileTypeProvider+CsvFileTypeProvider' reported an error: container type for 'CsvFileProvider.Row' was already set to 'CsvFileProvider.CsvFile,Filename="events.csv"

When I look at the code, I can’t see how I’m adding the Row type to the container twice (or to some other container). Removing selected lines of the code doesn’t help.

Here’s how I’m calling the code in fsi:

#r "CsvFileTypeProvider.dll"
open CsvFileProvider
let eventInfos = new CsvFile<"events.csv">() ;;

And here’s the code itself:

module CsvFileTypeProvider
open Samples.FSharp.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices

let getType str =
    if System.DateTime.TryParse(str, ref Unchecked.defaultof<_>) then
        typeof<System.DateTime>, (fun (str:Quotations.Expr) -> <@@ System.DateTime.Parse(%%str) @@>)
    elif System.Int32.TryParse(str, ref Unchecked.defaultof<_>) then
        typeof<System.Int32>, (fun (str:Quotations.Expr) -> <@@ System.Int32.Parse(%%str) @@>)
    elif System.Double.TryParse(str, ref Unchecked.defaultof<_>) then
        typeof<System.Double>, (fun (str:Quotations.Expr) -> <@@ System.Double.Parse(%%str) @@>)
    else
        typeof<string>, (fun (str:Quotations.Expr) -> <@@ %%str @@>)

[<TypeProvider>]
type CsvFileTypeProvider() =
    inherit TypeProviderForNamespaces()

    let asm = typeof<CsvFileTypeProvider>.Assembly
    let ns = "CsvFileProvider"

    let csvFileProviderType = ProvidedTypeDefinition(asm, ns, "CsvFile", None)
    let parameters = [ProvidedStaticParameter("Filename", typeof<string>)]

    do csvFileProviderType.DefineStaticParameters(parameters, fun tyName [| :? string as filename |] ->
        let rowType = ProvidedTypeDefinition(asm, ns, "Row", Some(typeof<string[]>))

        let lines = System.IO.File.ReadLines(filename) |> Seq.map (fun line -> line.Split(','))
        let columnNames = lines |> Seq.nth 0
        let resultTypes = lines |> Seq.nth 1 |> Array.map getType

        for idx in 0 .. (columnNames.Length - 1) do
            let col = columnNames.[idx]
            let ty, converter = resultTypes.[idx]
            let prop = ProvidedProperty(col, ty)
            prop.GetterCode <- fun [row] -> converter <@@  (%%row:string[]).[idx] @@>
            rowType.AddMember(prop)

        let wholeFileType = ProvidedTypeDefinition(asm, ns, tyName, Some(typedefof<seq<_>>.MakeGenericType(rowType)))
        wholeFileType.AddMember(rowType)

        let ctor = ProvidedConstructor(parameters = []) // the *type* is parameterized but the *constructor* gets no args
        ctor.InvokeCode <- //given the inputs, what will we get as the outputs? Now we want to read the *data*, skip the header
            fun [] -> <@@ System.IO.File.ReadLines(filename) |> Seq.skip 1 |> Seq.map (fun line -> line.Split(','))  @@>
        wholeFileType.AddMember(ctor)
        wholeFileType
        )

    do base.AddNamespace(ns, [csvFileProviderType])

[<TypeProviderAssembly>]
do()

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:54:52+00:00Added an answer on June 6, 2026 at 8:54 pm

    you need to use another constructor when defining ‘Row’ type. Existing ProvidedTypeDefinition type exposes two constructors:

    • (assembly, namespace, typename, base type) – defines top level type whose container is namespace.
    • (typename, basetype) – defines nested type that should be added to some another type.

    Now Row type is defined using first constructor so it is treated as top level type. Exception is raised when this type is later added to wholeFileType as nested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

recently I attended a talk on data-mining,and I missed some points by the lecturer,which
Recently I attended a lecture concerning some design patterns: The following code had been
I've recently been studying TDD, attended a conference and have dabbled in few tests
Recently I was asked to develop an app, which basically is going to use
Recently, I was writing a class in which I discovered that I could reduce
Recently I attended interview in java, the interviewer asked a question like below: I
I recently attended an interview and was asked the following question. There are two
I have recently attended a presentation where guy showed that .NET obfuscated code can
Recently i have attended an interview . A code snippet is given to me.I
I have recently attended an introductory course in using the iPhone SDK and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.