MCR and .NET incompatibility

I am trying to compile a Matlab application (R2010b) that uses a .NET module, but I had an incompatibility problem between the MCR and the .NET module:

  • The .NET module was compiled using Visual Studio 2010.
  • MCR is configured to use Visual Studio 2010.
  • The application also contains several Mex files that are built using Visual Studio 2010, and they work great in both Matlab and MCR.

If I load the assembly from Matlab cli, everything works fine, but as soon as I compile the application and run it from cmd.exe, I get a message that the assembly was built with a run time that is newer than the one that is currently loaded. I think the Matlab R2010b is built with Visual Studio 2008 and thinks this is a problem, but I wonder if anyone has a solution to the problem?

+8
matlab matlab-deployment matlab-compiler
source share
1 answer

The solution is to provide the application configuration file (foo.exe.config for the application named foo.exe) next to the compiled exe with the following entry:

<configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0"/> <supportedRuntime version="v2.0.50727"/> </startup> </configuration> 

The MATLAB.NET interface is built with the .NET framework 2.0, which means that in the absence of the application configuration file, 2.0 CLR is loaded. When running in MATLAB, the <supportedRuntime> entries from the configuration file tell MATLAB to load the 4.0 CLR, if available.

+7
source share

Source: https://habr.com/ru/post/650085/


All Articles