Why do I receive an error "Could not load file or assembly 'MWArray' or one of its dependencies" when attempting to run a 32-bit ASP.NET web application that calls a compiled .NET assembly, on a 64-bit server?

9 views (last 30 days)
I have compiled my MATLAB code into a .NET assembly using MATLAB Builder NE 3.0.2 (R2009b), on a 32-bit Windows machine. This assembly is then added as reference to a .NET Web Application which is compiled for an x86 target. When this web application is deployed to a 64-bit ASP.NET server and executed, I see the following exception:
System.BadImageFormatException: Could not load file or assembly 'MWArray' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 26 Jan 2010
As described in the Relation Solution linked below, .NET assemblies produced by MATLAB Builder NE (any release) are compiled into Microsoft Intermediate Language (MSIL), which make them architecture-independent. However, the compiled assembly typically has other platform-dependent dependencies, such as DLLs or MEX-files which limit the architecture on which it can be invoked. Therefore, you may only add assemblies produced from 32-bit MATLAB as References to projects compiled for the x86 Platform.
Also, when executing a 32-bit web application on a 64-bit server, it is launched by a 64-bit worker process (w3wp.exe) by default. However, since a .NET assembly compiled on a 32-bit machine has 32-bit dependencies, it is necessary for it to be launched by a 32-bit worker process.
To resolve this exception, one of two workarounds can be used:
1) Compile the .NET assembly using 64-bit MATLAB Builder NE, so that its dependencies are all 64-bit binaries.
2) Enable your server to run worker processes in both 64-bit and 32-bit mode, and apply a filter so that 32-bit applications are always launched by a 32-bit worker process.
Note: You can verify whether a worker process is running in 32-bit mode by monitoring processes in the Task Manager. All 32-bit processes are listed with an asterisk (*) adjacent to their names.

More Answers (0)

Categories

Find more on MATLAB Compiler SDK in Help Center and File Exchange

Products


Release

R2009b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!