Error when trying to run F# HTML Parser

New F# program with this line of code
let results = FSharp.Data.HtmlDocument.Load("http://www.google.com/search?q=FSharp.Data")
But I get a MissingMethodException
Method not found: 'FSharp.Data.HtmlDocument FSharp.Data.HtmlDocument.Load(System.String, Microsoft.FSharp.Core.FSharpOption`1)'.

Code runs ok in VSCode, Am I missing something ?
Seems like it is having some sort of issue with the optional parameter.

Comments

  • You need to add a reference to the FSharp.Data nuget package.
  • Sorry I should have been more explicit. I've added the FSharp.Data nuget, then added "open FSharp.Data" to the head of the file.
    Tried on 3 different machines
    Runs without error in VSCode or VStudio...
  • I can get past the above error if I use either the Load(reader:TextReader) or Load(stream:Stream) "overloads".
    However I get a similar error then trying to use the CssSelector function from the CssSelectorExtensions module.

    The error looks to me classic of a failure of c# reflection code failing to properly locate a method on a class. But I have no idea what/why such code would need to run on execution of a F# Program in Linqpad.

    Have also replicated the above issue in Linqpad 6

    Can anyone else confirm the error ?

    @JoeAlbahari I know you are probably busy with Linqpad 6, but if you can suggest a workaround that would be very helpful until the issue can properly identified and rectified ?
  • edited July 21
    Have found a terribly awful hack to get around the issue for now. This bit of reflection code invokes the right overload.
    //Gets the first CssSelect method (of three) from the static class and then invokes it by reflection.
    typeof.GetMethods().[0].Invoke(null, [| htmlDocument :> Object; "a" :> Object |])
    
  • The hack only goes so far as it returns an object, which then breaks all intellisense for later code. Tried to then cast it, but that fails with an invalid cast exception.
    [A]Microsoft.FSharp.Collections.FSharpList`1[FSharp.Data.HtmlNode] cannot be cast to [B]Microsoft.FSharp.Collections.FSharpList`1[FSharp.Data.HtmlNode]. Type A originates from 'FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'LoadFrom' at location 'C:\Users\xxx\AppData\Local\LINQPad\NuGet.FW46\FSharp.Data\FSharp.Core.4.0.0.1\lib\net40\FSharp.Core.dll'. Type B originates from 'FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'LoadNeither' in a byte array.
  • Just forced Linqpad to use the same fsc.exe that VS is using, thinking that this will make a difference to the above errors. But alas no improvement.

    @JoeAlbahari I need a suggestion. I've tried everything I can think of.
  • See this SO Post regarding the CssSelect issue.
  • In LINQPad 6, could you please run the following code:
    typeof.Assembly.GetName().Dump()
    typeof.Assembly.GetName().Dump()
    
    System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(typeof.Assembly).Dump()
    System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(typeof.Assembly).Dump()
    
    and tell me the output?

    Also, go to Query Properties, Advanced, and right-click the checkbox "Copy all NuGet references into single folder". This will bring up an assembly resolution log. Could you paste that in, too, please?
  • Just sent you a PM
  • For the reference of others landing here, you need to either 1. Include FSharp.Core from nuget or if you are running Linqpad 5.36.03 or earlier (should be fixex in latter releases), or 2. Run Linqpad 6.0.15 (beta) on wards.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!