MATLAB: Do I receive an error when I try to run the C# application that uses an assembly built by MATLAB Builder for .NET

32-bit64-bitbadimageformatexceptioncompatibilityMATLAB Builder NEnet

I have built an assembly using MATLAB Builder for .NET on a 32-bit machine. This assembly is being used by a C# application that is being built on a 64-bit machine. The application has the MATLAB Builder for .NET generated assembly referenced, and builds correctly. However, the following error is thrown at runtime:
System.BadImageFormatException was unhandled
Message="Could not load file or assembly 'MWArray, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=e1d84a0da19db86f' or one of its
dependencies. An attempt was made to load a program with an incorrect
format."
Source="MatLabConsoleApplication"
FileName="MWArray, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=e1d84a0da19db86f"

Best Answer

Components generated by the 32-bit builder products are not supported on 64-bit machines.
An assembly built using the MATLAB Builder for .NET on a 32-bit machine has a reference to a 32-bit MWArray assembly, which depends on the 32-bit native MCR libraries. As a result, this assembly should only be referenced in a 32-bit application. If referenced in a 64-bit application, the BadImageFormatException will be thrown by the application at runtime.