Compatibility .Net 4.0 and .Net 4.5. Could not load file or Assembly 'FSharp.Core, Version=4.3.1.0.'
I want to use the library Math.NET Symbolics in the F# project. But when I run simple code:
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
I have:
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.
I created a topic in the forum Math.NET
During the discussion, I thought it was impossible, because I only have .Net 4.5 and VS2012 (therefore I can't use F#3.1).
But I can't understand, if everything works in .Net 4.0, why I can not normal use in .Net 4.5. What about compatibility version?
Question: is it even possible? And, if possible, how?
Edit:
When app.config has:
<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" />
This code works fine:
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)
But I need to use a parser for mathematical expressions. Therefore, this option does not suit me.
Update:
Answer:
After an unsuccessful compile Visual Studio was changed reference to the FSharp.Core from package folder on a standard FSharp.Core 4.3.0.0. When I set the property "Copy Local" = "true" - problem was solved.
Now code
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
gives another exception:
System.TypeInitializationException: The type initializer for '<StartupCode$MathNet-Symbolics>.$Infix'
threw an exception. ---> System.Security.VerificationException: Operation could destabilize the runtime
I was looking for a mistake where it was not. The problem is not dependence. Because code without using FParces worked!
On the page for the package is written as follows:
"This package uses the basic "low-trust" configuration of FParsec, which does not use any unverifiable code and is optimized for maximum portability. If you need to parse very large files or if you employ FParsec for performance-critical jobs, consider using the alternate "Big Data Edition" NuGet package (see nuget.org/packages/fparsec-big-data-edition)."
So, I changed FParsec on FParsec (Big Data Edition) and everything works!
P.S. My attempts to change the binding redirect did not make sense =) just write:
<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
1 Answer 1
If Math.NET was compiled against 4.3.1.0, and you're stuck with Visual Studio 2012, which comes with 4.3.0.0, you have two options that I can think of:
- Grab the Math.NET source code, change it to target 4.3.0.0, and compile it.
- Install F# 3.1 into VS 2012
But you should really think about upgrading.
-
Thanks. Unfortunately, I have no way to update Visual Studio. I found the answer to my question, without recompiling Math.Net.FoggyFinder– FoggyFinder01/07/2016 16:33:12Commented Jan 7, 2016 at 16:33
-
Since it costs nothing to install a newer version of F# into Visual Studio, and it costs nothing to download the Community Edition of VS 2015, I have to assume it's your employer preventing you from using the tools you need to do your job. That doesn't reflect well on your employer.Joel Mueller– Joel Mueller01/07/2016 19:45:07Commented Jan 7, 2016 at 19:45
-
At the moment, programming for me is only a hobby . I don't have the ability to update Windows7, which will allow to install at least VS2013. But I plan to do this at the end of the month. Although, of course, the update creates some additional difficulties.FoggyFinder– FoggyFinder01/07/2016 20:58:54Commented Jan 7, 2016 at 20:58
-
@FoggyFinder - Why would you need to update Windows 7? Is it because VS 2015 requries Win7 SP1? That service pack is more than 5 years old...Joel Mueller– Joel Mueller01/07/2016 22:40:58Commented Jan 7, 2016 at 22:40
-
1I have quite an old laptop. And I'm afraid that if I change OS something goes wrong. I can't risk it now.FoggyFinder– FoggyFinder01/07/2016 23:38:26Commented Jan 7, 2016 at 23:38
Explore related questions
See similar questions with these tags.
FSharp.Core
do you have?FSharp.Core
matches .NET versions, see this answer: stackoverflow.com/a/20362049/126014FSharp.Core
, see this article: blog.ploeh.dk/2014/01/30/…