【问题标题】:Compatibility .Net 4.0 and .Net 4.5. Could not load file or Assembly 'FSharp.Core, Version=4.3.1.0.'兼容 .Net 4.0 和 .Net 4.5。无法加载文件或程序集“FSharp.Core,版本 = 4.3.1.0。”
【发布时间】:2016-01-06 16:23:11
【问题描述】:

我想在 F# 项目中使用库 Math.NET Symbolics。 但是当我运行简单的代码时:

open MathNet.Symbolics
open MathNet.Symbolics.Operators

...

let expr = Infix.parseOrThrow("sin(x) * y")
let symbols = Map.ofList [ "x", Real 2.0; "y", Real 3.0 ]
let res = Evaluate.evaluate symbols expr

我有:

Could not load file or Assembly ' FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\" or one of the dependent components. The system cannot find the file specified.

我在论坛Math.NET创建了一个话题

在讨论过程中,我认为不可能,因为我只有.Net 4.5和VS2012(因此我不能使用F#3.1)。

但我不明白,如果在 .Net 4.0 中一切正常,为什么我不能在 .Net 4.5 中正常使用。兼容版本呢?

问题:有可能吗?如果可能的话,怎么做?

编辑:

当 app.config 有:

<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
<bindingRedirect oldVersion="2.3.5.0" newVersion="4.3.0.0" />
<bindingRedirect oldVersion="2.0.0.0" newVersion="4.3.0.0" />

这段代码运行良好:

let symbols = Map.ofList [ "x", Real 2.0; "y", Real 3.0 ]
let x = symbol "x"
let y = symbol "y"
let res = Evaluate.evaluate symbols (sin(x) * y) 

但我需要对数学表达式使用解析器。因此,这个选项不适合我。

更新:

答案:

在编译失败后,Visual Studio 被更改为从标准 FSharp.Core 4.3.0.0 的包文件夹中引用 FSharp.Core。 当我设置属性 "Copy Local" = "true" - 问题就解决了。

现在代码

let expr = Infix.parseOrThrow("sin(x) * y")
let symbols = Map.ofList [ "x", Real 2.0; "y", Real 3.0 ]
let res = Evaluate.evaluate symbols expr

给出另一个例外:

System.TypeInitializationException: The type initializer for '<StartupCode$MathNet-Symbolics>.$Infix'
 threw an exception. ---> System.Security.VerificationException: Operation could destabilize the runtime

我一直在寻找一个没有的错误。问题不在于依赖。因为不使用 FParces 的代码有效!

On the page for the package的写法如下:

"这个包使用了 FParsec 的基本“低信任”配置, 它不使用任何无法验证的代码,并针对最大程度进行了优化 可移植性。如果您需要解析非常大的文件,或者如果您使用 FParsec 对于性能关键的作业,考虑使用备用 “大数据版”NuGet 包(请参阅 nuget.org/packages/fparsec-big-data-edition)。”

所以,我在FParsec (Big Data Edition) 上更改了 FParsec,一切正常!

附: 我尝试更改绑定重定向没有意义 =) 只需写:

<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />

【问题讨论】:

标签: visual-studio-2012 f# f#-3.0 fparsec math.net


【解决方案1】:

如果 Math.NET 是针对 4.3.1.0 编译的,并且您被 4.3.0.0 附带的 Visual Studio 2012 卡住了,那么我可以想到两个选项:

但是你真的应该考虑升级。

【讨论】:

  • 谢谢。不幸的是,我无法更新 Visual Studio。我找到了问题的答案,无需重新编译 Math.Net。
  • 由于在 Visual Studio 中安装较新版本的 F# 不需要任何费用,并且下载 VS 2015 的社区版不需要任何费用,我不得不假设是您的雇主阻止您使用您的工具需要做你的工作。这并不能很好地反映您的雇主。
  • 目前,编程对我来说只是一种爱好。我没有能力更新 Windows7,这将允许至少安装 VS2013。但我计划在月底这样做。当然,更新也会带来一些额外的困难。
  • @FoggyFinder - 为什么需要更新 Windows 7?是因为 VS 2015 需要 Win7 SP1 吗?该服务包已有 5 年以上的历史......
  • 我有一台相当旧的笔记本电脑。而且我担心如果我更改操作系统会出现问题。我现在不能冒险。
猜你喜欢
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-23
  • 1970-01-01
  • 1970-01-01
  • 2010-12-26
相关资源
最近更新 更多