我正在尝试解决一个预编译的F# Azure函数中的MissingMethodException问题。当我调用来自FSharp.Data.CssSelectorExtensions的扩展方法时,就会抛出此异常。
该函数定义在.NET Framework 4.6.2类库中。我正在使用当前版本的FSharp.Core(4.2.3)和FSharp.Data(2.3.3)。(我已经尝试过两者的旧版本,但问题仍然存在。)我已按照此类问题的标准指导添加了FSharp.Core的绑定重定向。代码可以编译通过,但在执行时失败。如果我尝试将扩展方法直接作为简单静态方法调用,它也会失败。
非常感谢任何关于如何消除此异常的指导!
功能代码
该函数定义在.NET Framework 4.6.2类库中。我正在使用当前版本的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包文件夹。
FSharp.Core
吗?也就是说,第二个版本会从哪里来? - John Hoerr