1

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" />
FoggyFinder
  • 2,230
  • 2
  • 20
  • 34

1 Answers1

3

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.

Community
  • 1
  • 1
Joel Mueller
  • 28,324
  • 9
  • 63
  • 88
  • Thanks. Unfortunately, I have no way to update Visual Studio. I found the answer to my question, without recompiling Math.Net. – FoggyFinder Jan 07 '16 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 Jan 07 '16 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 Jan 07 '16 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 Jan 07 '16 at 22:40
  • 1
    I have quite an old laptop. And I'm afraid that if I change OS something goes wrong. I can't risk it now. – FoggyFinder Jan 07 '16 at 23:38