首页 文章

FSharp.Data缺少方法异常

提问于
浏览
3

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

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

任何有关如何摆脱此异常的指导将非常感激!

Function Code

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

Exception Message

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>

Edit

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

Two versions of FSharp.Core.dll are loaded.

1 回答

  • 1

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

    我可能会遗漏一些东西,但我认为你最好的机会是让你的功能使用版本4.4.0.0 . 您可以尝试删除显式 FSharp.Core 引用吗?这样,运行时应该只加载 FSharp.Core 的(已经预加载的)版本 .

相关问题