如何在dotnet核心中解决'System.MissingMethodException'

时间:2018-10-07 14:45:53

标签: f# .net-core system.drawing accord.net

要复制,请执行以下步骤:

在终端/ cli中:

dotnet new console --language F# --name "sample"
cd sample
dotnet add package Accord.Imaging
dotnet add package CoreCompat.System.Drawing --version 1.0.0-beta006

下载image之后的文件,并将其放入项目文件夹。

更改Program.fs以包含以下代码:

// Learn more about F# at http://fsharp.org

open System
open System.Drawing
open Accord.Imaging.Filters

[<EntryPoint>]
let main argv =
    let bitmap = new Bitmap("sample8.jpg")
    let filter = new Grayscale( 0.2125, 0.7154, 0.0721 );
    let sourceImage = filter.Apply(bitmap)
    printfn "Hello World from F#!"
    0 // return an integer exit code

如何解决以下错误?

Unhandled Exception: System.MissingMethodException: Method not found: 'System.Drawing.Color[] System.Drawing.Imaging.ColorPalette.get_Entries()'.
   at Accord.Imaging.Image.SetGrayscalePalette(Bitmap image)
   at Accord.Imaging.Image.CreateGrayscaleImage(Int32 width, Int32 height)
   at Accord.Imaging.Filters.BaseFilter.Apply(BitmapData imageData)
   at Accord.Imaging.Filters.BaseFilter.Apply(Bitmap image)
   at Program.main(String[] argv) in /dev/sample/Program.fs:line 11

1 个答案:

答案 0 :(得分:0)

您需要使用Corecompat.System.Drawing.v2 version=5.2.0-preview1-r131程序集而不是CoreCompat.System.Drawing version version=1.0.0-beta006

在相关的.fsproj文件中,包括:

<PackageReference Include="CoreCompat.System.Drawing.v2" Version="5.2.0-preview1-r131" />

并删除对此任何与之冲突的对其他CoreCompat.System.Drawing程序集的引用,然后还原解决方案中的nuget。