简体   繁体   中英

Call Matlab Function from C# error : The type initializer for 'tes.tambah' threw an exception

I am getting the

"The type initializer for 'tes.tambah' threw an exception.."

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MathWorks.MATLAB.NET.Arrays;
using tes;

namespace panggil_lib_matlab
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
                tambah tbh = new tambah(); 
        }
    }
}

and this my Matlab Code:

function [ hasil ] = coba( a,b )
    hasil = a+b;
end

I get error on this line: tambah tbh = new tambah(); and this is the 'InnerException' message:

System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at MathWorks.MATLAB.NET.Arrays.MWArray.mclmcrInitialize2(Int32 primaryMode) at MathWorks.MATLAB.NET.Arrays.MWArray..cctor() --- End of inner exception stack trace --- at MathWorks.MATLAB.NET.Utility.MWMCR..cctor() --- End of inner exception stack trace --- at tes.tambah..cctor()

I use:

  • Windows 8.1 64-bit
  • Visual Studio Ultimate 2012 (32-bit, I think)
  • Matlab R2015a 64-bit

Can anyone help me?

确保您的应用程序定位到x64而不是AnyCPU

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM