3

I've compiled a little program using matlab 2013 I can see in my dll: Test.TestMethods all my functions

I've added it as a reference to my dot net project, and added the MWArray dll from matlab bin\win64\v2.0 folder.

** Update: The app crushes at this line in the matlabe generated code:

mcr= new MWMCR("", ctfFilePath, embeddedCtfStream, true);

If I embed the ctf file - it will crush, if I don't embed it, it will throw an exception.

I've set my program to build against X64.

Once I try to create the object:

Test.TestMethods test = new Test.TestMethods();

My App crashes. I can only see in external Visual Studio instance:

Unhandled exception at 0x0000000001D36E60 (m_interpreter.dll). 
Access violation reading location 0x00000000A5CE3920.

I have no idea where to start....

EDIT1: this is the ctor (there is also a static cctor):

    .method public hidebysig specialname rtspecialname 
        instance void  .ctor() cil managed
{
  // Code size       20 (0x14)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
  IL_0006:  ldsfld     class [mscorlib]System.Exception Test.TestMethods::ex_
  IL_000b:  brfalse.s  IL_0013
  IL_000d:  ldsfld     class [mscorlib]System.Exception Test.TestMethods::ex_
  IL_0012:  throw
  IL_0013:  ret
} // end of method TestMethods::.ctor
Dani
  • 14,639
  • 11
  • 62
  • 110
  • Your question is a little vague. What is `Test.TestMethods`? Is `MWArray` a managed dll or native? How are you calling into `MWArray`? Can you post the code from `TestMethods`s' constructor? – Tejas Sharma Jun 20 '13 at 17:21
  • this is a generated function by the matlab compiler. I can try to ildisasmble it.. – Dani Jun 20 '13 at 17:26
  • Hmm well just make sure you've copied over ALL dependencies into your current working directory (eg. `MWArray` might have a dependency on one of the other dlls present in the matlab folder). Try copying over all the dlls and see if that makes a difference. – Tejas Sharma Jun 20 '13 at 17:29
  • Tried the TestNative Dll as well. Same thing. – Dani Jun 20 '13 at 17:43
  • Have you tried http://ilnumerics.net? I never touched the whole Matlab compiler thing again and use only pure managed code since then. little reason to continue to torture yourself ... just my 2C – user492238 Jun 20 '13 at 17:48
  • Checking, but i hope to be able to run matlab from dot net... it can't be that difficult. – Dani Jun 20 '13 at 17:51
  • Dont know whether that applies to you.. in a project I am aware of, the problem is that dependencies need to be created when starting an app for the first time (you will see a generated subfolder), for the second run from same folder, everything is fine. (In the end, it looks like MCR is a lot of hassle. Still no solution for that problem.) – Andreas Reiff Jul 03 '13 at 20:15
  • Yep, generated folder with _mcr suffix is created. But application is still crashing during a MCR initialization: new MWMCR(..) with an access violation error inside m_interpreter.dll – Konstantin Tarkus Jul 09 '13 at 02:26
  • I have exactly the same problem. How did you fix it? – ekim boran May 20 '15 at 13:14

1 Answers1

1

You cannot call MATLAB generated .NET libraries from .NET 4.5 assemblies, also it crashes when VS debugger is attached.

Konstantin Tarkus
  • 37,618
  • 14
  • 135
  • 121
  • My application is targeted for .NET framework v4.6.1 and it crashes exactly at the point where a new object for the class exported by MATLAB, is instantiated. Once I moved down to .NET framework v4.0, it worked. – Rajaraman Subramanian Nov 01 '17 at 11:43