F#用户代码中的MethodMissingException;怎么样?

时间:2017-05-29 19:22:37

标签: .net f# .net-core

我写了几个简单的F#项目。我们称他们为ConsoleLibrary

Console是一个非常简单的控制台应用程序,目标是netcoreapp2.0。这是项目文件Console.fsproj

<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="../Library/Library.fsproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="FSharp.Core" Version="4.1.*" />
    <PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
  </ItemGroup>

</Project>

来源,Program.fs

open System
open Library

[<EntryPoint>]
let main argv =
    let result = Stats.ema 0.0 [3.7; 8.9]
    0 // return an integer exit code

现在,Library.fsproj

<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Library.fs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="FSharp.Core" Version="4.1.*" />
    <PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
  </ItemGroup>

</Project>

Library.fs

module Library.Stats

let ema (prevEma:float) (values:float list) =
    0.0

我可以很好地恢复这两个项目(仅使用nuget.org),并且构建工作也很好:

C:\Users\ben\proj\scratch
λ  dotnet build
Microsoft (R) Build Engine version 15.3.117.23532
Copyright (C) Microsoft Corporation. All rights reserved.

  Library -> C:\Users\ben\proj\scratch\src\Library\bin\Debug\netstandard2.0\Library.dll
  Console -> C:\Users\ben\proj\scratch\src\Console\bin\Debug\netcoreapp2.0\Console.dll

但是,在运行时,程序会抛出MissingMethodException

C:\Users\ben\proj\scratch\src\Console
λ  dotnet run

Unhandled Exception: System.MissingMethodException: Method not found: 'Double Library.Stats.ema(Double, Microsoft.FSharp.Collections.FSharpList`1<Double>)'.
   at Program.main(String[] argv)

这是我的dotnet --info

C:\Users\ben\proj\scratch\src\Console
λ  dotnet --info
.NET Command Line Tools (2.0.0-preview1-005977)

Product Information:
 Version:            2.0.0-preview1-005977
 Commit SHA-1 hash:  414cab8a0b

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.0-preview1-005977\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0-preview1-002111-00
  Build    : 1ff021936263d492539399688f46fd3827169983

造成这种情况的原因是什么?

更新

从评论中可以看出,我发现有冲突的引用是System.Runtime而不是FSharp.Core,并且引用是在SDK或工具中的某处添加的。

我还没有找到一个好的答案,我在dotnet/netcorecli-fsc存储库上打开了一个问题。

0 个答案:

没有答案