I'm trying out f# on a mac and am running into a problem with a very simple script. I'm following this tutorial, however it breaks at results.Descendants ["a"].
Interestingly, VS recognises .Descendants as a valid method of results, but at runtime (trying just Descendants with no params) I get:
error CS1061: 'HtmlDocument' does not contain a definition for 'Descendants' and no
extension method 'Descendants' accepting a first argument of type 'HtmlDocument' could
be found (are you missing a using directive or an assembly reference?)
It seems as if FSharp.Data is only partially imported or something. Interestingly, HtmlDocument works, but extensions don't.
Any ideas how to fix this?
Edit: code
// Learn more about F# at http://fsharp.org
open System
open FSharp.Data
[<EntryPoint>]
let main argv =
let results = HtmlDocument.Load("http://www.google.co.uk/search?q=FSharp.Data")
let links =
results.Descendants "a"
|> Seq.choose (fun x ->
x.TryGetAttribute("href")
|> Option.map (fun a -> x.InnerText(), a.Value())
)
0 // return an integer exit code
Edit2: I downloaded FSharp.Data with nuget manually and I can run the below script in fsharpi. I don't know what's the difference between this and whatever visual studio does?
#r "./FSharp.Data.2.4.6/lib/net45/FSharp.Data.dll"
open FSharp.Data
let results = HtmlDocument.Load("http://www.google.co.uk/search?q=FSharp.Data")
let d= results.Descendants "a"
Edit 3: The differences between running in fsharpi and vs:
I can't seem to force VS to use FSharp.Core 4.0.0.1. Even if I add specific version, it still uses 4.3.4
It seems the problem is in FCore.Sharp Visual Studio is using by default. To use specific version, it's not enough to add it through nuget, but one must add
<FSharpCoreImplicitPackageVersion>4.4.1.18</FSharpCoreImplicitPackageVersion>
to the project config. With that it seems the code works, but debugger (watch window) and immediate window still fail to recognise Descendants method. I don't know how that's even possible. I assume some kind of bug in VS.
Another option seems to be using FSharp.Data 3 beta (with the same watch/immediate problem)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With