[英]Error when running Matlab script in C# Windows Application
I'm trying to run a Matlab script in Visual Studio C# Windows Application. 我正在尝试在Visual Studio C#Windows应用程序中运行Matlab脚本。 I have run the Matlab Compiler to build my script and obtained the dll (tryingLF).
我已经运行Matlab编译器来构建我的脚本并获得了dll(tryingLF)。 Below is my code for trying to run the script when I click on a button in C#:
以下是我在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); }
}
}
}
However, when I tried to run the C# program, I got an error called "The type initializer for 'tryingLF.Class1' threw an exception." 但是,当我尝试运行C#程序时,出现了一个错误消息:“ tryingLF.Class1的类型初始化程序引发了异常。” Why is this so?
为什么会这样呢? Any help would be much appreciated!
任何帮助将非常感激! Thank you.
谢谢。
Check the ex.InnerException
property and it should have more details on what exactly is causing the type initialization exception. 检查
ex.InnerException
属性,它应该详细了解究竟是什么导致类型初始化异常。
One possibility is that Class1 needs some stuff to get initialized and it cannot find one of them. 一种可能是Class1需要一些东西来初始化,而找不到其中之一。 so it goes crazy.
因此变得疯狂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.