Can't use Matlab DLL's in MC.Net

Questions about MultiCharts .NET and user contributed studies.
SysInv
Posts: 28
Joined: 25 Nov 2012
Has thanked: 1 time
Been thanked: 1 time

Can't use Matlab DLL's in MC.Net

Postby SysInv » 23 Jan 2014

After speaking with support yesterday where they pretty much only said "check your dependencies" and that they do not offer support on custom DLL, I decided to post my problem here instead. I understand you don't offer support on this, but the fact that it works just fine in standalone solution and I can call it from other .Net third party software without these problems makes me doubt it's the DLL that is the problem.

In short - I'm trying to use a function written in Matlab, compiled to a .Net DLL and call it from MC.Net.

I originally did this on a x64 machine, where it works fine. The deployment needs to be done on a x86 however, which is where the problem arise. As soon as I run it from MC a dialogue box saying "the specific module could not be found".

This sounds like a dependency problem, but:
If I create a 32bit console application calling the two DLL's, everything works fine.
If I move the same code to the MC.Net project, referencing the exact same DLL's (from the same catalog) I get the error.

Now:
Both solutions run on .Net 4.0
Both solutions have X86 as build (I've tried setting it to Any CPU as well)
Both solutions has the exact same code for using the function
Both solutions has the exact same references
I've made sure that the same references are added in the PL editor as MC doesn't pick up references added in Visual Studio

I know that a Matlab DLL needs to have the JIT turned off, which I usually do in the AssemblyInfo file. However it worked on the x64 MC without doing this, and if the JIT was the problem then I would get an exception when preparing the Matlab matrices before calling the function, and not just this error box when using the actual functions.

I've also made sure that the Matlab variables are registered as environment variables in Windows.

Oh, and checking the dependencies on the Matlab DLL's show there are no errors or missing DLL's. Using the same solution in other .Net trading platforms works fine as well.

Sure, it might still be a dependencies problem, but my original question to support was what is different in the environment that MC runs in compared with a standalone solution, since MC gives an error...

Maybe support can have another look at this, or if some user have had similar problems?

Thanks.

SysInv
Posts: 28
Joined: 25 Nov 2012
Has thanked: 1 time
Been thanked: 1 time

Re: Can't use Matlab DLL's in MC.Net

Postby SysInv » 25 Jan 2014

Since I needed this up and running asap, I decided to implement another library for the optimizations (Microsoft Solver Foundation). This library is distributed from Microsoft and well integrated in the windows environment, where the library is available as a Global Reference. There is only one library to reference: Microsoft.Solver.Foundation.dll

Again, the optimization works fine in a standalone project. However, when I run the exact same code from inside Multicharts problems arise.

To set up the model, we need create an environment and then a model in this environment. This is done with:

SolverContext context = SolverContext.GetContext();
Model model = context.CreateModel();

The fact that we get this far without error, and since it works in a standalone solution should mean that it's no problem with dependencies (and the library needed is only a single global one). However, as we continue with the model to create a decision variable we get a problem:

Decision x1 = new Decision(Domain.IntegerNonnegative, "x1");

The problem is when using the Domain which is a class to define what kind of values the variable can take on. When running this, it throws a System.TypeInitializationException. These exceptions usually indicate a problem when a static constructor in the class throws an exception. The model is set up correctly according to Microsoft (I even tried with one of their samples).

It is something in the MC environment that are causing problems for third party libraries since it works fine otherwise and from other trading platforms.

I've tried on two different 32bit computers now, and both have the latest MC.Net installed.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Can't use Matlab DLL's in MC.Net

Postby Henry MultiСharts » 27 Jan 2014

The information required for further analysis of the case has been requested via email.


Return to “MultiCharts .NET”