简体   繁体   English

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

[英]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.

相关问题 运行c#windows应用程序时出错 - Error in running c# windows application 如何在C#Windows应用程序中调用和运行Matlab脚本 - How to call and run Matlab script in C# Windows Application 在Windows 7上以Parallels 8错误运行C#Windows窗体应用程序 - Running a C# Windows Forms application on Windows 7 in Parallels 8 error C#应用程序未在Windows 7上运行 - C# Application not running on windows 7 在Windows 2003 Server上运行C#应用程序时出错 - Error while running C# application on windows 2003 server 如何在Linux上运行的python脚本与Windows上运行的.NET C#应用程序之间建立通信? - How to establish communication between a python script running on Linux with a .NET C# application running on windows? 脚本在Powershell中运行,但在C#中运行时出错 - Script running in Powershell but error when run in C# 从C#运行Azure脚本时出现“未实现方法”错误 - “Method not implemented” error when running Azure script from c# 在C#中运行Web应用程序时出现服务器错误 - Server Error in web application program when running it in C# 运行C#应用程序访问网络摄像头时遇到此错误消息 - Encountered this error message when running a C# application accessing the webcam
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM