3

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 
        }
    }
}
Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
Jonas
  • 1,365
  • 3
  • 21
  • 39

1 Answers1

2

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
Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • added successfull compile example on Win64 – sehe Nov 23 '11 at 13:08
  • I forgot to mention I'm using VS2008, 32bit, and I'm trying to compile as a .NET 2.0 application – Jonas Nov 23 '11 at 13:31
  • AFAICT the zip file contains _explicitely_ Net40 and SL4 binaries only... I doubt whether more is supported – sehe Nov 23 '11 at 13:33
  • **Update** No it isn't. MathNet depends on [System.Numerics](http://msdn.microsoft.com/en-us/library/system.numerics.aspx) which is .Net 4.0+ – sehe Nov 23 '11 at 13:45
  • TypeLoadException is a runtime exception, not a compile-time error. – Hans Passant Nov 23 '11 at 13:46
  • 1
    @HansPassant: Clear. Of course it is. Which is why I tested _running it_ too. Note that the framework version was a late addition by the OP ? – sehe Nov 23 '11 at 13:47
  • Math.NET Numerics: .Net 4.0+, Portable: Silverlight 5+ or Metro; Math.NET Iridium: .Net 2.0+ – Christoph Rüegg Aug 26 '12 at 18:35