Using MATLAB MWArray.dll in C# Class Library

三世轮回 提交于 2019-12-05 22:33:13
Nitay

What helped me was to make sure the C# application and the matlab modules are under the same architecture - Meaning 32 or 64 bit.

If your Matlab is 64 bits - Try changing the C# project to 64 bit

See this post: Creating a shared library (.NET Assembly) in Matlab and using it in C#

I'm working through the same problem and, in my case, it appears to be something in a .csproj file, strange as it sounds.

In general I suggest the following be tried: Create a new Windows Forms app and add the enclosed code. Don't forget to add the reference to MWArray.dll. Run the code and if an exception is thrown then you have an installation problem with the Matlab runtime or the x86 / x64 versions of the runtime and built application don't match. (You indicate you already did this but this is a general answer designed to help others also)

Add the enclosed code to program.cs of your application and see if it throws an exception. Continue progressing towards the DLL that throws the exception until an exception is thrown.

When an exception is finally thrown, verify that the x86 / x64 of the project matches that of the Matlab runtime.

If the x86 / x64 versions match, create a new DLL project with a different class name whose constructor has the same signature as the failing DLL. Add the enclosed code to the new DLL, unwire the failing DLL and wire in this new DLL, and run the application. If the code doesn't throw an exception then you probably have a problem in the .csproj file or another DLL. Copy and paste chunks of code from the failing DLL into the new one and retest for an exception. Continue until all code has been copied or until the exception returns. If the exception returns, continue troubleshooting to find the offending line of code. If all code has been copied then you have a functioning DLL. You should be able to take it from there to get rid of the failing DLL and replace it with the new functioning DLL.

I hope this helps! Zack

using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;


try
{
    MWNumericArray oMW = new MWNumericArray();
}
catch (Exception ex)
{

}

So this magically started happening on a Windows server in which nothing was changed on the server for weeks.

The solution for me, after ripping my eyes out, was to set the "Enable 32-Bit Applications" setting in the web sites application pool to FALSE. Once I did that, everything worked and I placed my eye balls back into their sockets.

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