MATLAB dll 与 64 位机器中的 asp.net 网站的集成给出异常 [英] MATLAB dll integration with asp.net website in 64 bit machine giving exception
问题描述
我有一个问题:我在 Matlab 中创建了一个函数,我想在 asp.net
中使用它.
它在 32-bit
机器上运行良好,但是当我将它传输到 64-bit
机器时它不工作.
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 与 asp.net
网站在 64 位
机器上的集成给出了一个例外,但在 32 位
上没有机器.
Matlab-dll integration with asp.net
website on a 64-bit
machine gives an exception, but not on a 32-bit
machine.
背景
我正在尝试学习如何将 Matlab 代码集成到 C# 中.我使用的是 Matlab R2010a 和 Visual Studio 2010.我从 Matlab 文件交换下载了教程 并执行了代码的 Matlab 部分.
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.
但是,当我尝试在 Visual Studio 中编译 C# 代码时,出现以下错误:
However, when I tried to compile the C# code in visual studio, I got the following error:
无法加载文件或程序集MWArray,版本=2.9.1.0,文化=中性,PublicKeyToken=e1d84a0da19db86f"或其依赖项之一.该系统找不到指定的文件.
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.
通过谷歌快速搜索,我找到了 this mathworks page,它指示我将目标处理器更改为 x86.
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 未处理
System.BadImageFormatException was unhandled
Message="无法加载文件或程序集 'MWArray,版本 = 2.0.0.0,Culture=neutral, PublicKeyToken=e1d84a0da19db86f' 或其中之一依赖关系.试图加载一个不正确的程序格式."
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."
我的 MatLab 版本是 64 位,但我仍然遇到这个问题.有解决方法吗?
My MatLab version is 64 bit, but I am still encountering this problem. Is there a workaround?
推荐答案
尝试使用这个
从 C# 创建的应用程序被编译为托管代码,这使得它们独立于平台(例如 Java).因此,当您在 32 位机器上编译 C# 应用程序,然后将其部署到 64 位机器上时,默认情况下,它将尝试作为 64 位应用程序运行.然后,它会尝试查找 64 位版本的 MWArray.dll,如果失败,将显示上述错误.
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.
要解决此问题,请在编译 C# 应用程序之前将选项属性 -> 构建 -> 平台目标"设置为x86"而不是任何 CPU".这将导致应用程序在 64 位机器上以 32 位模式启动.
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.
这篇关于MATLAB dll 与 64 位机器中的 asp.net 网站的集成给出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!