The type 'XmlProvider' is not defined

f#, f#-data, type-providers

Solution

The parameter between `<>` is the `Sample` parameter of the type provider, which has to be a compile time constant. That sample is used to infer the structure of the xml.

Try this instead:

namespace KMyMoney

open FSharp.Data

module Read =

    type KMyMoneySource = XmlProvider<"KMyMoneySampleFile.xml">

and then do

let xml = KMyMoneySource.Load("KMyMoneySampleFile.xml")

or if you're reading the same file you used as the XmlProvider sample parameter, just do this:

let xml = KMyMoneySource.GetSample() 

Note that Type Providers are a feature of F# 3.0, so this only works in VS2012 or upper. If you're using VS2010, you'll just get a bunch of syntax errors.

Problem

I'm trying to use the `FSharp.Data` third party library but am getting an error `The type 'XmlProvider' is not defined` on the `XmlProvider` class. ``` namespace KMyMoney open FSharp.Data module Read = let xml = File.ReadAllText("KMyMoneySampleFile.xml") type KMyMoneySource = XmlProvider<xml> ``` I'm using NuGet to get the library. Library is 'FSharp.Data 1.1.8' When I type `FSharp.Data.` There are four options given: `Csv`, `FreebaseOperators`, `Json`, and `RuntimeImplementation`. Am I missing something? I'm relatively new to F#. So, sorry for the simple question. I've looked on GitHub but haven't seen any mention of this problem. I am creating a library in F#.

Original source