Visual studio 2012 兼容.Net 4.0和.Net 4.5。无法加载文件或程序集';FSharp.Core,版本=4.3.1.0.&x27;

Visual studio 2012 兼容.Net 4.0和.Net 4.5。无法加载文件或程序集';FSharp.Core,版本=4.3.1.0.&x27;,visual-studio-2012,f#,f#-3.0,fparsec,math.net,Visual Studio 2012,F#,F# 3.0,Fparsec,Math.net,我想在F#项目中使用库Math.NET符号。 但当我运行简单代码时: open MathNet.Symbolics open MathNet.Symbolics.Operators 我有: Could not load file or Assembly ' FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\" or one of the dependent components. Th

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

open MathNet.Symbolics
open MathNet.Symbolics.Operators

我有:

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.
我在论坛上创建了一个主题

在讨论中,我认为这是不可能的,因为我只有.NET4.5和VS2012(因此我不能使用F#3.1)

但我不明白,如果在.NET4.0中一切正常,为什么我不能在.NET4.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" />
但是我需要为数学表达式使用解析器。因此,这个选择不适合我

更新:

回答:

编译失败后,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
System.TypeInitializationException:“$Infix”的类型初始值设定项
引发了异常。-->System.Security.VerificationException:操作可能会使运行时不稳定
我一直在寻找一个错误,但事实并非如此。问题不在于依赖。因为没有使用FParces的代码是有效的

全文如下:

“此软件包使用FParsec的基本“低信任”配置, 它不使用任何无法验证的代码,并针对最大 可移植性。如果您需要解析非常大的文件或 FPARSEC用于性能关键作业,考虑使用备用 “大数据版”NuGet软件包(参见 org/packages/fparsec大数据版)

所以,我换了FParsec,一切正常

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

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

如果Math.NET是根据4.3.1.0编译的,而您仍然使用4.3.0.0附带的Visual Studio 2012,那么我可以想到两个选项:

  • 获取Math.NET源代码,将其更改为目标4.3.0.0,然后进行编译

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

@Hans Passant,我读了几遍。然后看了其他类似的问题。抱歉,我不明白如何帮助您了解这些信息。您有哪个版本的
FSharp.Core
?有关
FSharp.Core
的各种版本如何与.NET版本匹配的详细概述,请参阅以下回答:有关如何重定向
FSharp.Core
的程序集绑定的信息,请参阅本文:谢谢。不幸的是,我没有办法更新VisualStudio。我在没有重新编译Math.Net的情况下找到了问题的答案。因为在Visual Studio中安装更新版本的F#不需要任何费用,下载VS 2015社区版也不需要任何费用,所以我不得不假设是你的雇主阻止你使用工作所需的工具。这对你的雇主不太好。目前,编程对我来说只是一种爱好。我没有能力更新Windows7,这将允许安装至少VS2013。但我计划在月底做这件事。当然,更新会带来一些额外的困难。@FoggyFinder-为什么需要更新Windows 7?是因为VS 2015需要Win7 SP1吗?那个服务包已经5年多了……我有一台相当旧的笔记本电脑。我担心如果我改变操作系统,会出问题。我现在不能冒险。
System.TypeInitializationException: The type initializer for '<StartupCode$MathNet-Symbolics>.$Infix'
 threw an exception. ---> System.Security.VerificationException: Operation could destabilize the runtime
<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />