代码之家  ›  专栏  ›  技术社区  ›  red-swan

如何解析具有PlatformNotSupportedException的程序集?

  •  1
  • red-swan  · 技术社区  · 6 年前

    我是一个爱上了F的数学家。然而,网络组装却让我悲伤。我不明白他们是怎么纠缠在一起的。所以我想逃跑 an example from Infer.Net

    Binding session to 'C:\Users\jdks\.nuget\packages\system.codedom\4.4.0\lib\netstandard2.0\System.CodeDom.dll'...
    > System.PlatformNotSupportedException: Current platform is not supported by the current compiler choice Auto. Try a different one. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
       at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
       at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames)
       at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.CompileWithCodeDom(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
       at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.Compile(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
       --- End of inner exception stack trace ---
       at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.Compile(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
       at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.WriteAndCompile(List`1 typeDeclarations)
       at Microsoft.ML.Probabilistic.Compiler.ModelCompiler.CompileWithoutParams[T](List`1 itds)
       at Microsoft.ML.Probabilistic.Models.InferenceEngine.Compile()
       at Microsoft.ML.Probabilistic.Models.InferenceEngine.GetCompiledInferenceAlgorithm(Boolean inferOnlySpecifiedVars, IVariable var)
       at Microsoft.ML.Probabilistic.Models.InferenceEngine.Infer[TReturn](IVariable var)
       at <StartupCode$FSI_0003>.$FSI_0003.main@() in C:\Temp\Script1.fsx:line 24
    Stopped due to error
    

    剧本如下:

    #r "netstandard.dll"
    #r @"C:\Users\jdks\.nuget\packages\system.codedom\4.4.0\lib\netstandard2.0\System.CodeDom.dll"
    #r @"C:\Users\jdks\.nuget\packages\microsoft.ml.probabilistic\0.3.1810.501\lib\netstandard2.0\Microsoft.ML.Probabilistic.dll"
    #r @"C:\Users\jdks\.nuget\packages\microsoft.ml.probabilistic.compiler\0.3.1810.501\lib\netstandard2.0\Microsoft.ML.Probabilistic.Compiler.dll"
    #r @"C:\Users\jdks\.nuget\packages\microsoft.ml.probabilistic.learners\0.3.1810.501\lib\netstandard2.0\Microsoft.ML.Probabilistic.Learners.dll"
    #r @"C:\Users\jdks\.nuget\packages\microsoft.ml.probabilistic.visualizers.windows\0.3.1810.501\lib\net461\Microsoft.ML.Probabilistic.Compiler.Visualizers.Windows.dll"
    #r @"C:\Users\jdks\Proto\infer-master\src\FSharpWrapper\bin\Debug\netstandard2.0\Microsoft.ML.Probabilistic.FSharp.dll"
    
    open System
    open Microsoft.ML.Probabilistic
    open Microsoft.ML.Probabilistic.Distributions
    open Microsoft.ML.Probabilistic.Models
    
    let firstCoin = Variable.Bernoulli(0.5)  
    let secondCoin = Variable.Bernoulli(0.5)
    let bothHeads = firstCoin &&& secondCoin
    let engine = new InferenceEngine()
    
    // this is the line that fails
    let bothHeadsPost = engine.Infer<Bernoulli>(bothHeads)
    
    printfn "Both heads posterior = %A" bothHeadsPost
    bothHeads.ObservedValue <- false
    

    如您所见,我使用了Infer.Net的nuget包,但是下载了git repo并编译它以获得 FSharpWrapper.dll . 既然我能编译,我猜问题与程序集有关,但我还不知道如何解决问题。我该怎么办?

    :
    - From the Infer.Net github repo :核心包以.NET Standard 2.0为目标,使其可用于任何以.NET framework 4.6.1版或.NET core 2.1版为目标的项目


    它说的是什么意思 Binding session to ... ? 我在Expert F#4.0或在线上找不到任何好的信息,看起来很可疑。

    1 回复  |  直到 6 年前
        1
  •  3
  •   Phillip Carter    6 年前

    原因有两个:

    1. netstandard2.0 net461 ,这将解决这类问题。

    我建议将此软件包与您运行的.NET Core控制台应用程序一起使用(手动或与 dotnet-watch-run 工具)。