2

I am trying to parse string of expression using MathNet in C# and when I try this code:

var h = MathNet.Symbolics.Infix.ParseOrUndefined("1/(a*b)");

it threw exception.

"An unhandled exception of type 'System.TypeInitializationException' occurred in MathNet.Symbolics.dll

Additional information: The type initializer for '.$Infix' threw an exception."

Where am I wrong? I used MathNet v.0.6.0.0 and Visual Studio 2012 Express

Updated

It was solved by hotfix by windows which is my bad not to update.

TylerH
  • 20,799
  • 66
  • 75
  • 101

2 Answers2

0

There seems to be something wrong with the dependencies. Can you list what exact package versions of them you're using? And what .Net version you're compiling against.

Assuming you have installed Math.NET Symbolics via NuGet, can you try to update all dependencies (with NuGet)?

Edit: I cannot reproduce this with newer VisualStudio versions - is there a chance you could upgrade, e.g. to VisualStudio Community which is free as well?

Christoph Rüegg
  • 4,626
  • 1
  • 20
  • 34
  • all of the dependencies are updated. this is the log i got System.TypeInitializationException: The type initializer for '.$Infix' threw an exception. ---> System.Security.VerificationException: Operation could destabilize the runtime. at FParsec.InfixOperator`3..ctor(String operatorString, FSharpFunc`2 afterStringParser, Int32 precedence, Associativity associativity, FSharpFunc`2 mapping) at .$Infix..cctor() – Renton Thurston Oct 03 '15 at 15:32
  • Ok, now, that's another beast. There have been issues causing this, but to my understanding have been fixed by hotfixes - is your system up to date with all windows updates? – Christoph Rüegg Oct 03 '15 at 16:00
  • aw! I see. Thank you. :) i forgot to search for solution of internal exception not the external. My bad. – Renton Thurston Oct 03 '15 at 17:31
  • Can you try again with v0.7.1 (and FParsec 1.0.1 and the proper FSharp.Core)? – Christoph Rüegg Oct 03 '15 at 17:31
  • It is working now with hotfix. Thank you. :) – Renton Thurston Oct 03 '15 at 17:33
  • Great to hear, thanks! – Christoph Rüegg Oct 03 '15 at 17:35
-1

I guess you must using that syntax:

 var H = MathNet.Symbolics.Infix.Parse "1/(a*b)";

Interesting note that the above function will return 1/(a*b) and not the solution of that calculation. If you want H have the result, you must use:

 var H = MathNet.Symbolics.Infix.Parse "1/(a*b)";
 MathNet.Symbolics.Infix.Print(H);
David BS
  • 1,822
  • 1
  • 19
  • 35
  • Thank you for the response. I edited the question and I just followed what said here. [link](http://symbolics.mathdotnet.com/). but getting the error – Renton Thurston Oct 03 '15 at 13:48
  • Is MathNet correctly referenced in form (at top, USING MATHNET)? Are A and B correctly initialized? Are MathNet and NET Framework the same version? – David BS Oct 03 '15 at 13:55
  • Yes it is. "Infix.Print()" method works and other methods but "Infix.ParseOrUndefined" and "Infix.ParseOrThrow" threw and exception. – Renton Thurston Oct 03 '15 at 14:10
  • It can be related to the version of Infix. Try to update it or try to utilize only the Parse function (not ParseOrThrow or ParseOrUndefined). I understand both functions can be answering 100% IF AND JUST IF you have problems with that variables - in this case, the first returns a ThrowException and the second returns Undefined... – David BS Oct 03 '15 at 14:17
  • There's nothing wrong with the way the library is used in the question. – Christoph Rüegg Oct 03 '15 at 15:15