Why do I get an 'incorrect format' error when trying to reference MWArray from MATLAB Builder NE 4.0 (R2011a)?

11 views (last 30 days)
I have compiled my MATLAB function into a .NET assembly using MATLAB Builder NE 4.0 (R2011a). Now I want to use it in a web application. However, I get the following error when trying to reference the MWArray.dll (the additional assembly needed by the web application to call my compiled assembly).
c:\users\administrator\documents\visual studio 2010\Projects\WebApplication1\WebApplication1\WebForm1.aspx: ASP.NET runtime error: Could not load file or assembly 'MWArray' or one of its dependencies. An attempt was made to load a program with an incorrect format.
I am using a 64-bit MATLAB on a 64-bit Windows Server 2008. Microsoft Visual Studio Professional 2010 is used to develop the web application. I have made sure that the compiled assembly and the MWArray.dll being referenced are the correct 64-bit versions. MWArray.dll is also correctly added to the GAC.
I tried to set the 'Target Platform' in Visual Studio to x64, but the only option available is 'Any CPU'. How can I solve this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 3 Dec 2018
The 'incorrect format' error usually means that some 64-bit process is trying to call a 32-bit process, or vice versa.
Unlike normal programs, web applications run on a host server. The 'incorrect format' error can be given if the host server architecture does not match the web application (or any of its dependencies) architecture. In this case, the default Microsoft Visual Studio web development server is available only in 32-bit. In order to develop 64-bit web applications, another server must be used.
A good server is Microsoft's Internet Information Services (IIS) server, available on all Windows systems. IIS is usually disabled by default. Follow the steps below to activate it and configure it in the Microsoft Visual Studio environment (instructions based on Windows 7):
1. To enable IIS, go to Start > Control Panel > Programs and Features > Turn Windows Features On or Off. This will start the Windows Features manager window. Selections should look like below:
Hit OK. A restart may be required.
2. Open the IIS Manager by going through Start > type 'Internet Information Services' in the search field > select IIS Manager. You should see the IIS Manager window, with the system name and server tree on the left hand side.
3. Setup the appropriate application pool (group of sites or web applications that are served by one or more worker processes). Right click on Applicatoin Pools > Add Application Pool. You should see the window below.
Give a name for the pool, select the target .NET framework version, then hit OK. Pipeline mode should be classic if Web Figures are used.
4. Set the architecture of the application pool. Select the application pool > click Advanced Settings... on the right side.
'Enable 32-Bit Applications' should be 'False' to run 64-bit applications.
5. Setup your web application in the IIS Manager. Select Sites > Right click on Default Web Site > Add Application. This should open the window below:
In the 'Alias' field, enter the name of the site. Select the 64-bit application pool you just created in the 'Application pool' field. Add the physical path of the web site into the 'Physical path' field (the folder where the web application project lives). Hit OK.
6. Confirm the site settings. Select the site > click on Advanced Settings... on the right hand pane. You should see the window below.
'Virtual Path' is the URL of the site relative to the host. In this case, it would be:
"http://localhost/WebApplication3"
7. Configure Visual Studio to use the IIS server. In Visual Studio, open the project properties > Web > Servers > select 'Use Local IIS Web server'.
In the 'Project Url' field, enter the virtual path of the web site previously set up in the IIS manager.
This should complete the process to allow Visual Studio to develop 64-bit web applications and reference 64-bit assemblies, such as MWArray from 64-bit MATLAB.

More Answers (0)

Products


Release

R2011a

Community Treasure Hunt

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

Start Hunting!