I am trying to compile a Matlab (R2010b) application that uses a .NET module, but I am facing a problem with incompatibility between the MCR and the .NET module:
If I load the assembly from the Matlab cli everything work just fine, but once I compile the app and run it from cmd.exe an error is thrown stating that the assembly is built with a runtime that is newer than the one currently loaded. I think that Matlab R2010b is built with Visual Studio 2008 and believe that this is the problem, but I wonder if anyone has a solution to the problem?
The solution is to provide an application config file(foo.exe.config for application called 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>
MATLAB .NET interface is built with .NET framework 2.0, which means that in the absence of an app config file the 2.0 CLR is loaded. When running in MATLAB the <supportedRuntime>
entries from the config file tells MATLAB to load 4.0 CLR if available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With