FSharp.Data 缺少方法异常

FSharp.Data missing method exception

我正在尝试解决预编译的 F# Azure 函数中的 MissingMethodException。当我从 FSharp.Data.CssSelectorExtensions 调用扩展方法时抛出异常。

函数在 .Net Framework 4.6.2 class 库中定义。我使用的是 FSharp.Core (4.2.3) 和 FSharp.Data (2.3.3) 的当前版本。 (我已经尝试了两者的旧版本,但问题仍然存在。)我根据此类问题的标准指南为 FSharp.Core 添加了绑定重定向。代码编译干净,但在执行时失败。如果我尝试将扩展方法作为简单的静态方法直接调用,它也会失败。

任何关于如何摆脱此异常的指导将不胜感激!

函数代码

module httpfunc

open System.Net
open System.Net.Http
open Microsoft.Azure.WebJobs.Host
open FSharp.Data
open FSharp.Data.CssSelectorExtensions

let Run(req: HttpRequestMessage, log: TraceWriter) =
    async {
        let doc = HtmlDocument.Load("https://google.com")
        let node = doc.CssSelect("div.ctr-p") // <-- method is missing
        return req.CreateResponse(HttpStatusCode.OK)
    } |> Async.RunSynchronously

异常消息

 mscorlib: Exception while executing function: Functions.httpfunc. 
 mscorlib: Exception has been thrown by the target of an invocation. 
 fsfuncs: Method not found: 'Microsoft.FSharp.Collections.FSharpList`1<FSharp.Data.HtmlNode> CssSelectorExtensions.CssSelect(FSharp.Data.HtmlDocument, System.String)'.

app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.4.1.0" newVersion="4.4.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="FSharp.Core" version="4.2.3" targetFramework="net462" />
  <package id="FSharp.Data" version="2.3.3" targetFramework="net462" />
  ...
</packages>

.fsproj

<Project ToolsVersion="15.0" ... />
  <PropertyGroup>
    <RootNamespace>fsfuncs</RootNamespace>
    <AssemblyName>fsfuncs</AssemblyName>
    <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
    <TargetFSharpCoreVersion>4.4.1.0</TargetFSharpCoreVersion>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Name>fsfuncs</Name>
  </PropertyGroup>
  ...
</Project>

编辑

根据 Fyodor Soikin 的建议,我确定正在加载 FSharp.Core.dll 的多个版本:一个来自 GAC,一个来自 NuGet 包文件夹。

Azure Functions 背后的执行引擎已经加载 FSharp.Core.dll(因为它依赖于 F# 编译器服务来 运行 您的 F# 脚本),我认为您将始终获得 [=10= 的版本]即由execution engine's app.config指定的,即4.4.0.0。

我可能遗漏了一些东西,但我认为最好的机会是让您的函数使用 4.4.0.0 版。您可以尝试删除显式 FSharp.Core 引用吗?这样,运行time 应该只加载 FSharp.Core.

的(已经预加载的)版本