Can't get MWNumericArray out of c#

9 次查看(过去 30 天)
Dan
Dan 2016-10-7
评论: Para Kan 2019-10-23
I have this very simple test C# code that is supposed to get the number 24 into MATLAB
public MWNumericArray test() { int data = 24; MWNumericArray array = data; return array; }
When I run test from MATLAB I get this error:
Error using mbm.sqlApache_Cassandra/test (line 24) Message: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWNumericArray' threw an exception. Source: MWArray HelpLink:
When I get the full errorcode from c# it looks like this:
{System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWNumericArray' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception. ---> System.Exception: Trouble initializing libraries required by .NET Assembly.
at MathWorks.MATLAB.NET.Utility.MWMCR..cctor()
--- End of inner exception stack trace ---
at MathWorks.MATLAB.NET.Arrays.MWArray..cctor()
--- End of inner exception stack trace ---
at MathWorks.MATLAB.NET.Arrays.MWNumericArray.get__Inf()
at MathWorks.MATLAB.NET.Arrays.MWNumericArray..cctor()
--- End of inner exception stack trace ---
at MathWorks.MATLAB.NET.Arrays.MWNumericArray.op_Implicit(Int32 scalar)
at cassandra_sql.csql.test() in c:\Mercurial\MBM\c#\cassandra_sql\cassandra_sql\csql.cs:line 81}
Any idea what to do ?
  1 个评论
SGH
SGH 2017-4-26
编辑:SGH 2017-4-26
I have the same problem. I'm using VS 2015, compiling the .net assembly in x64, target .net 4.5.2, running matlab 2015 x64. Attaching the VS debugger to matlab the constructor for MWStructArray fails to instantiate. When I run my C# code from a unit test and write that same MWStructArray to a *.mat file (using a matlab function compiled into a .net assembly), the *.mat file loads the MWStructArray just fine in matlab. However, I can not get the MWStructArray straight up from my .net assembly. I ONLY have one installation of Matlab (v2015 x64), one installation of the Matlab runtime (v9 == v2015).
Has anyone been able to get an MWStructArray from a .net assembly?

请先登录,再进行评论。

回答(1 个)

Prasad Mendu
Prasad Mendu 2016-10-17
One of the possible reasons for this error is the bitness mismatch between Visual Studio and the DLL. The Visual Studio has to be of 64-bit to run a 64-bit DLL. By default Visual Studio is a 32-bit application and while installing it you can check the option for 'x64'.
If you have not already done so, you can go to Configuration Manager check to see which option is selected 'x64' or 'x86'. You can also change the build configuration in Visual Studio to set the Target Platform to 'x64' instead of 'x86'.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by