Noaman Akram
Noaman Akram

Reputation: 3830

MATLAB dll integration with asp.net website in 64 bit machine giving exception

I have a a problem: I have created a function in Matlab which I want to use in asp.net.
It is working fine on a 32-bit machine but when I transfer it to a 64-bit machine it is not working.

Matlab-dll integration with asp.net website on a 64-bit machine gives an exception, but not on a 32-bit machine.

Background

I'm trying to learn how to integrate Matlab code into C#. I'm using Matlab R2010a and Visual Studio 2010. I downloaded a tutorial from the Matlab File Exchange and executed the Matlab part of the code.

However, when I tried to compile the C# code in visual studio, I got the following error:

Could not load file or assembly 'MWArray, Version=2.9.1.0, Culture=neutral, PublicKeyToken=e1d84a0da19db86f' or one of its dependencies. The system cannot find the file specified.

A quick google search led me to this mathworks page, which instructed me to change the target processor to x86.

However, as soon as I did so, I received a new error:

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."

My MatLab version is 64 bit, but I am still encountering this problem. Is there a workaround?

Upvotes: 1

Views: 2099

Answers (1)

Shyam sundar shah
Shyam sundar shah

Reputation: 2523

try to use this

Applications created from C# are compiled as managed code, which makes them platform independent (like Java, for example). Thus, when you compile a C# application on a 32-bit machine and then deploy it on a 64-bit machine, it will, by default, try to run as a 64-bit application. Then, it will try to find the 64-bit version of the MWArray.dll, and if it fails, the mentioned error will be shown.

To work around this issue, set the option "Properties -> Build -> Platform target" to "x86" instead of "Any CPU" before compiling your C# application. This will have the effect that the application will start in 32-bit mode on the 64-bit machine.

Upvotes: 2

Related Questions