主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

诊断消息

下表显示了您可能会遇到的诊断消息、消息的可能原因以及建议的解决方案。

有关一些诊断消息的信息请参阅下表。

诊断消息和建议的解决方案

消息可能的原因建议的解决方案
LoadLibrary("component_name_1_0.dll") failed - The specified module could not be found.

从 DOS 提示符注册工程 DLL 时可能会收到此错误消息。如果 MATLAB® Runtime 不在系统路径上,则可能会出现这种情况。

在安装了 MATLAB 的系统上,matlabroot\runtime\arch 必须位于系统路径中,位于任何其他 MATLAB 安装之前。

在安装了 MATLAB 运行时的系统上,请确保 matlabroot\release\runtime\arch 已添加到系统路径中。

(matlabroot 是您的根目录 MATLAB 或 MATLAB 运行时文件夹。)

Mathworks.MATLAB.NET.name could not be found.

您可能需要在 Visual Studio® 工程中引用 MWArray.dll 程序集。

添加对位于 matlabroot\toolbox\dotnetbuilder\bin\arch\v4.0MWArray.dll 程序集的引用。

Error in component_name.class_name.x: Error getting data conversion options.

这通常是由于 mwcomutil.dll 未注册造成的。

  1. 打开 DOS 窗口。

  2. 将文件夹更改为 matlabroot\bin\win64

  3. 运行以下命令:mwregsvr mwcomutil.dll

Error in VBAProject: ActiveX component can't create object.
  • 工程 DLL 未注册。

  • 系统路径上的某处存在不兼容的 MATLAB DLL。

如果 DLL 未注册,

  1. 打开 DOS 窗口。

  2. 将文件夹更改为 projectdir\distrib

  3. 运行以下命令:mwregsvr projectdll.dll

projectdir 代表您的工程文件的位置)。

object ref not set to instance of an object

当调用尚未实例化的对象时,会发生这种情况

实例化对象。

Error in VBAProject: Automation error The specified module could not be found.

如果 MATLAB 不在系统路径上,通常会发生这种情况。

在已安装 MATLAB 的系统中,请确保 matlabroot\runtime\arch 位于系统路径中,且位于所有其他 MATLAB 安装之前。

Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.

当 ASP.NET 代码尝试调出对话框时会出现此警告。

发生这种情况的原因是 getframe() 在执行捕获之前使图形窗口可见,因此在 MATLAB 中运行时会失败。MATLAB 代码中的 msgbox() 调用也会导致出现警告。

通过执行以下操作来解决此问题:

  1. 打开 Windows 控制面板。

  2. 开放服务。

  3. 从服务列表中,选择并打开 IIS Admin 服务。

  4. 在“属性”对话框的登录选项卡上,选择本地系统帐户

  5. 选择选项允许服务与桌面交互

使用 mstack Trace 增强错误诊断

使用此增强的诊断功能来排除 MATLAB 代码执行期间专门发生的问题。

要实现此功能,请使用 .NET 异常处理来调用 .NET 应用程序内部的 MATLAB 函数,如下 try-catch 代码模块所示:

try 
{ 
Magic magic = new Magic(); 
magic.callmakeerror(); 
} 
catch(Exception ex) 
{ 
Console.WriteLine("Error: {0}", exception); 
} 

发生错误时,MATLAB 代码堆栈跟踪会在 Microsoft® .NET 应用程序堆栈跟踪之前打印,如下所示:

... MATLAB code Stack Trace ... 
    at 
file C:\work\MagicDemoCSharpApp\bin\Debug\
CalldmakeerrComp_mcr\compiler\g388611\ca 
thy\MagicDemoComp\dmakeerror.m,name 
dmakeerror_error2,line at 14. 
    at 
file C:\work\MagicDemoCSharpApp\bin\Debug\
CalldmakeerrComp_mcr\compiler\work\MagicDemoComp\dmakeerror.m,name 
dmakeerror_error1,line at 11. 
    at 
file C:\work\MagicDemoCSharpApp\bin\Debug\
CalldmakeerrComp_mcr\compiler\work\MagicDemoComp\dmakeerror.m,name dmakeerror,line at 4. 
    at 
file C:\work\MagicDemoCSharpApp\bin\Debug\
CalldmakeerrComp_mcr\compiler\work\MagicDemoComp\calldmakeerror.m,name 
calldmakeerror,line at 2. 

... .Application Stack Trace ... 
   at MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction
(String functionName, Int32 numArgsOut, Int 
32 numArgsIn, MWArray[] argsIn) 
   at MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction
(Int32 numArgsOut, String functionName, MWA 
rray[] argsIn) 
   at CalldmakeerrComp.Calldmakeerr.calldmakeerror() in 
C:\work\MagicDemoComp\src\ 
Calldmakeerr.cs:line 140 
   at MathWorks.Demo.MagicSquareApp.MagicDemoApp.Main(String[]
 args) in C:\work\Ma 
gicDemoCSharpApp\MagicDemoApp.cs:line 52