Exception when initialize dll in c# generated by MATLAB Compiler

有些话、适合烂在心里 提交于 2019-12-18 07:24:24

问题


I used the MATLAB Compiler to generate a .NET Assembly with a very little MATLAB code:

function output_arg = extest( input_arg1,input_arg2 )
    output_arg = input_arg1+input_arg2;
end

I generated the dll with the wizard.

Within my Visual Studio project I added the reference to the generated dll (extest.dll) and to the MATLAB Runtime dll (C:\Program Files\MATLAB\MATLAB Runtime\v92\toolbox\dotnetbuilder\bin\win64\v4.0\MWArray.dll) as mentioned in the "Assembly Description".

This is my c# code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MathWorks.MATLAB.NET.Utility;
using extest;

namespace DllTesting
{
    class Program
    {
        static void Main(string[] args)
        {
            ExClass e1 = new ExClass();
        }
    }
}

It builds without errors an intelisense is working (so all references should be good from my understanding)

But when I launch it, the following exception gets thrown (on new ExClass()):

An unhandled exception of type 'System.TypeInitializationException' occurred in DllTesting.exe

Additional information: The type initializer for 'extest.ExClass' threw an exception.

Any suggestions what is wrong with this code or whats missing?


回答1:


Try adding this before the class definition

[assembly: MathWorks.MATLAB.NET.Utility.MWMCROption("-nojit")]

Also make sure that the .NET version you use for assembly is the same or lower than the one used for your Visual Studio project.

Another solution might be adding the path of the MATLAB runtime (e.g. C:\Program Files\MATLAB\MATLAB Runtime\v92\runtime\win64) to the PATH Environment Variable.

If none of these helps, have a look here and here, you might have a 64/32 bit mismatch.



来源:https://stackoverflow.com/questions/44680338/exception-when-initialize-dll-in-c-sharp-generated-by-matlab-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!