Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can anyone explain why I get TypeLoad Exception while using MathNet.com Numerics Library?

I get a strange System.Action TypeLoadException while multiplying two matrixes, Can anyone help?

I created a new project in VS2008, 32bit, and changed target framework to 2.0, include MathNet.Numerics.dll and execute the fallowing code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Numerics;
using MathNet.Numerics.Statistics;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Double.Factorization;

namespace MathNetTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double[,] A = new double[3, 3];

            A[0, 0] = 1;
            A[0, 1] = 0.2;
            A[0, 2] = 1;
            A[1, 0] = 1.5;
            A[1, 1] = -1.2;
            A[1, 2] = 1.1;
            A[2, 0] = 0.45;
            A[2, 1] = 2.1;
            A[2, 2] = -0.76;

            Matrix XA = new DenseMatrix(A);
            Matrix XB = new DenseMatrix(A);

            Matrix C = (Matrix)(XA * XB); // throws a TypeLoadException 
        }
    }
}
like image 347
Jonas Avatar asked Feb 21 '26 13:02

Jonas


1 Answers

Update

MathNet.Numerics requires .NET Framework #4.0 for System.Numerics support.

I have no such problem on Mono/MS.NET #4.0 (see examples below)

This is with the libs downloaded from google code

If my answer doesn't help you, check for conflicting versions of MathNet in the GAC, and preferrably set the references t

  • Copy Local = true
  • Sepcific Version = true

Mono 2.10.x:

Minimal tetst program (console application):

using MathNet.Numerics.LinearAlgebra.Double;

public class Program
{
    public static void Main(string[] args)
    {
        double[,] A = new double[3, 3];

        A[0, 0] = 1;
        A[0, 1] = 0.2;
        A[0, 2] = 1;
        A[1, 0] = 1.5;
        A[1, 1] = -1.2;
        A[1, 2] = 1.1;
        A[2, 0] = 0.45;
        A[2, 1] = 2.1;
        A[2, 2] = -0.76;

        Matrix XA = new DenseMatrix(A);
        Matrix XB = new DenseMatrix(A);

        Matrix C = (Matrix)(XA * XB); // throws a TypeLoadException 
    }
}

Compiled with

dmcs -optimize+ -reference:MathNet.Numerics.dll test.cs

Runs fine

Win64 MS.NET 4.0:

Update Also no problem on VS2010 (WinXP 64):

T:\lib\Net40>csc test.cs -reference:MathNet.Numerics.dll
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.


T:\lib\Net40>.\test.exe
like image 174
sehe Avatar answered Feb 23 '26 03:02

sehe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!