Reputation: 69
I've been trying to get the MathNet.Numerics library to work. I keep getting this weird run time error every time I try to initialize a matrix. I have scoured the internet for post of similar problems, without any luck. This have made me believe that I probably have missed something potentially obvious. I will describe how I included the library as well as the code that creates the error, although I don't believe the code is the problem since it is taken from the math.net example site of how to use a matrix.
So! I've tried two methods of importing the library. The first one is to open the NuGet Package Manager Console and writing Install-Package MathNet.Numerics That's it! The second method was to open the Manage NuGet Packages. Then search for mathnet.numerics and then install it. To me this does the exact same thing as the previous method, right?
Anyhow now the library seems to be imported and it is because I can build the following code without any errors.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MathNet.Numerics.LinearAlgebra; // Maybe unnecessary to include this one as well as the one below
using MathNet.Numerics.LinearAlgebra.Double;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
Matrix<double> A = DenseMatrix.OfArray(new double[,] {
{1,1,1,1},
{1,2,3,4},
{4,3,2,1}});
Vector<double>[] nullspace = A.Kernel();
}
}
}
Then I build it, and this might be where the problem is. I have my suspicions! I just build it, i.e. right click the solution and Build! No Errors!
Then when I run the program, I get the following exception when the DeseMatrix.OfArray.... is excecuted.
An unhandled exception of type 'System.TypeInitializationException' occurred in MathNet.Numerics.dll Additional information: The type initializer for 'MathNet.Numerics.LinearAlgebra.Storage.MatrixStorage`1' threw an exception.
So to conclude this rather long question: What am I missing?
PS. The project has to be run with .Net 3.5. Don't worry, I have also tried to do this exact same thing in .net 4.5. Also I've tried this solution on several computers, both win 7 and 8.
Upvotes: 1
Views: 2566
Reputation: 58
I had this problem today. I needed to add the TaskParallelLibrary. Right-click references, manage nuget packages and search for taskparallel online. This fixed it for me. Appears to be a dependency.
Upvotes: 1