【问题标题】:Keep getting runtime error from MathNet Numerics library. Can't seem to get it to work不断从 MathNet Numerics 库中获取运行时错误。似乎无法让它工作
【发布时间】:2014-07-15 10:21:40
【问题描述】:

我一直在尝试让 MathNet.Numerics 库工作。每次尝试初始化矩阵时,我都会收到这个奇怪的运行时错误。我已经在互联网上搜索过类似问题的帖子,但没有任何运气。这让我相信我可能错过了一些可能很明显的事情。我将描述我是如何包含库的以及产生错误的代码,尽管我不认为代码是问题所在,因为它取自 math.net 示例网站,介绍了如何使用矩阵。

所以!我尝试了两种导入库的方法。第一个是打开 NuGet 包管理器控制台并编写 Install-Package MathNet.Numerics 就是这样!第二种方法是打开 Manage NuGet Packages。然后搜索 mathnet.numerics 然后安装它。对我来说,这与以前的方法完全相同,对吧?

无论如何,现在库似乎已导入,这是因为我可以构建以下代码而不会出现任何错误。

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();
        }
    }
}

然后我构建它,这可能就是问题所在。我有我的怀疑!我只是构建它,即右键单击解决方案并构建!没有错误!

然后当我运行程序时,当 DeseMatrix.OfArray.... 被执行时,我得到以下异常。

MathNet.Numerics.dll 中出现“System.TypeInitializationException”类型的未处理异常 附加信息:“MathNet.Numerics.LinearAlgebra.Storage.MatrixStorage`1”的类型初始化程序引发了异常。

所以总结一下这个相当长的问题:我错过了什么?

PS。该项目必须使用 .Net 3.5 运行。别担心,我也尝试在 .net 4.5 中做同样的事情。我也在多台计算机上尝试过这个解决方案,包括 win 7 和 8。

【问题讨论】:

    标签: c# .net mathnet-numerics


    【解决方案1】:

    我今天遇到了这个问题。我需要添加 TaskParallelLibrary。右键引用,管理nuget包,在线搜索taskparallel。 这为我修好了。似乎是一个依赖项。

    【讨论】:

    • TaskParallelLibrary 是一个依赖项,但仅适用于 .Net 3.5 构建。注意,在目标框架之间切换时,需要重新安装NuGet包(Update-Package -Reinstall)
    猜你喜欢
    • 2012-06-09
    • 1970-01-01
    • 2011-11-30
    • 2015-09-20
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多