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#.
The parameter between
<>
is theSample
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:
and then do
or if you're reading the same file you used as the XmlProvider sample parameter, just do this:
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.
The data has to be available at compile-time which is achieved by putting a file reference in the angle brackets like this (notice that it is a string literal containing a file path, not a string binding containing the data). You can also achieve this by putting a string literal containing the format in the brackets:
See here for more information.
Check out this link. Basically you need to add
System.Xml.Linq.dll
also as reference to your project.