MATLAB: What bitness MATLAB Runtime should be used with the compiled .NET library

anycpuassemblyMATLAB Compiler SDK

I compiled a .NET library using MATLAB Compiler SDK, and it appears that both the compiled library and the MWArray.dll dependency are compiled for AnyCPU, meaning they can run in both 32-bit and 64-bit environments.
If I compile my library with R2015b or earlier, how do I know which MATLAB Runtime is required if both 32-bit and 64-bit runtimes are available? What about when I compile with R2016a or later?

Best Answer

For libraries compiled with MATLAB R2015b and earlier versions, the MATLAB Runtime that is required will depend on the bitness of the driver application (the application that uses the library). If the application runs as 32-bit, then the 32-bit MATLAB Runtime is required, and if it runs as 64-bit then the 64-bit Runtime is required.
If both 32-bit and 64-bit MATLAB Runtimes are installed, the runtime that is higher on the system path will be found first and used, and this may result in an error if the bitness of this Runtime does not match the bitness of the driver application.
If the library is compiled with R2016a or later, then only 64-bit MATLAB Runtime is available and the compiled library can only be used by 64-bit applications.