如何使用PlatformNotSupportedException解析程序集?

时间:2018-11-12 16:48:16

标签: .net f#

我是一个爱上F#的数学家。 .NET程序集使我感到悲痛。我不明白他们是如何纠缠和解决的。因此,我尝试运行an example from Infer.Net,并尝试将其转换为脚本时,在Visual Studio 2017中将其运行到FSI中时遇到以下错误:

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 个答案:

答案 0 :(得分:2)

有两个原因:

  1. 存储库中有关此软件包的声明带有一个大星号。 .NET Standard 2.0和.NET Framework 4.7或更低版​​本存在很多问题。出于所有目的和目的,此程序包仅应与.NET Core或.NET Framework 4.7.1+一起使用;请参见参考资料。否则,您可能会期望看到更多问题。软件包作者可能应该将多个目标同时定位到netstandard2.0net461,这将解决此类问题。
  2. F#Interactive目前尚未正确支持.NET Standard组件。这是我们正在努力的工作,但是这是一个很难解决的问题,我希望适当的支持至少要稳定几个月。

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

相关问题