在 C# Windows 应用程序中运行 Matlab 脚本时出错

本文关键字:Matlab 脚本 出错 运行 Windows 应用程序 | 更新日期: 2023-09-27 17:55:25

我正在尝试在Visual Studio C# Windows应用程序中运行Matlab脚本。我已经运行了Matlab编译器来构建我的脚本并获得了dll(tryingLF)。下面是我在 C# 中单击按钮时尝试运行脚本的代码:

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 tryingLF;      //dll
namespace LinkMatlabandC
{
public partial class Form1 : Form
{
    Class1 linking = null;
    public Form1()
    {
        InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            linking = new Class1();
            linking.loadForecast();
        }
        catch (Exception ex)
        { MessageBox.Show(ex.Message); }
    }
}
}

但是,当我尝试运行 C# 程序时,我收到一个名为"'tryingLF.Class1' 的类型初始值设定项引发异常"的错误。为什么会这样?任何帮助将不胜感激!谢谢。

在 C# Windows 应用程序中运行 Matlab 脚本时出错

检查 ex.InnerException 属性,它应该有关于导致类型初始化异常的确切原因的更多详细信息。

一种可能性是 Class1 需要一些东西来初始化,但它找不到其中之一。 所以它变得疯狂。