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 t开发者_如何学编程he .NET module:
- The .NET module is compiled with Visual Studio 2010.
- MCR is configured to use Visual Studio 2010.
- The application also contain a few Mex-files that are built with Visual Studio 2010 and they work just fine both in Matlab and with MCR.
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.
精彩评论