FoggyFinder
FoggyFinder

Reputation: 2220

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" />

Upvotes: 1

Views: 352

Answers (1)

Joel Mueller
Joel Mueller

Reputation: 28735

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:

But you should really think about upgrading.

Upvotes: 3

Related Questions