c# - 谁能解释为什么我在使用 MathNet.com Numerics Library 时出现 TypeLoad Exception?

标签 c# exception math.net

我在将两个矩阵相乘时得到一个奇怪的 System.Action TypeLoadException,有人可以帮忙吗?

我在 VS2008 中新建了一个项目,32 位,并将目标框架更改为 2.0,包括 MathNet.Numerics.dll 并执行以下代码:

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 
        }
    }
}

最佳答案

Update

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

我在 Mono/MS.NET #4.0 上没有这样的问题(见下面的例子)

这是从 google code 下载的库。

如果我的回答对您没有帮助,请在 GAC 中检查 MathNet 的冲突版本,最好将引用设置为 t

  • 复制本地 = true
  • 具体版本 = true

单声道 2.10.x:

最小的测试程序(控制台应用程序):

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 
    }
}

编译为

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

运行良好

Win64 MS.NET 4.0:

更新 在 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

关于c# - 谁能解释为什么我在使用 MathNet.com Numerics Library 时出现 TypeLoad Exception?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8242496/

相关文章:

c# - 如何从另一个方法调用按钮单击事件

c# - 在 Windows 移动设备上写入错误日志文件的最佳方法是什么?

c++ - c++中抛出的对象在哪里?

java - String.matches() 引发 PatternSyntaxException?

java - 我正在尝试读取一个文本文件,然后拆分行,以便获得两组不同的名称

performance - 如何重构代码以使其具有功能性风格?

c# - 从服务连接到 SQLExpress

c# - 在 C#.NET 中使用正则表达式从字符串中提取数据

symbolic-math - 使用 Math.NET Symbolics 求解线性方程

c# - 使用 mathdotnet 进行互相关