I've created a .NET assembly in Matlab (2014a) using the Application Compiler, and I'm trying to use it under C#.
The matlab module has only 1 function:
function [ val ] = AnalyzePicture( arg1 )
val = 5;
end
The exported .NET DLL is named AnalyzePicture.dll and exports Class1 (as defined in the Matlab application compiler). However, when I try to initialize it, I get an exception saying:
The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception
With the inner exception saying:
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Here's the code
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AnalyzePicture;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
namespace Analyzer
{
public class MatlabWrapper
{
AnalyzePicture.Class1 analyzer = null;
public MatlabWrapper()
{
try
{
// The exception is raised here
analyzer = new AnalyzePicture.Class1();
}
catch (System.Exception ex)
{
MessageBox.Show("f");
}
}
...
My project references MWArray (8.3, the current version) and the AnalyzePicture dll (and DirectShowLib-2010).
I tried to find solutions online but i couldn't find a decent example on how to properly use a Matlab .NET Assembly in C#. I did exactly as described in this article besides that my assembly does not start with com.
Any ideas on what could be causing the problem? Any code examples will be greatly appriciated
(I'm using Windows 7 64bit, with Matlab 2014a 8.3 64bit)