필터 지우기
필터 지우기

Why Matlab executable cannot load .NET library? The DLL path is correct.

조회 수: 19 (최근 30일)
Jingliang Zhang
Jingliang Zhang 2015년 10월 14일
답변: KAE 2024년 3월 13일
I wrote a GUI in Matlab and it works fine. But after I compiled it to .exe. It causes error because it cannot load .NET library (I find it out by running .exe in command prompt).
I am testing the .exe on the same computer that compiles the .exe. And the right version of MCR is installed. The error occurs at this line of code: "A = NET.addAssembly(dll_directory);" where 'dll_directory' is the path of dll file I want to load. I checked the 'dll_directory' path during the run of .exe and it is correct.
When I run Line - "A = NET.addAssembly(dll_directory);" in Matlab, there is no error.
Any suggestion on this?
  • I have read this blog 'http://blogs.mathworks.com/loren/2008/08/11/path-management-in-deployed-applications/' which is very informative. But since the dll path is shown correctly during the run, I think the issue is not because of path management. It makes me to doubt if it is because a particular Matlab license? I tried to look documentation for 'ctfroot' and I don't have proper license to view content.

답변 (2개)

Rohit Kudva
Rohit Kudva 2015년 10월 19일
Hi Jingliang,
One possible reason can be that while compiling the code to create a standalone executable, you may have not added the DLL file as a required file for your standalone application. Use the '-a' option to add the DLL file while compiling your code with the 'mcc' command
>> mcc -m mytest -a NetSample.dll
In case if you have already added the file using the '-a' option, the path of the DLL file from the view of the standalone application will be different from its actual path on your local file system. When you add files to the archive using '-a' that do not appear on the MATLAB path at the time of compilation, a path entry is added to the application's run-time path so that they appear on the path when the deployed code executes.
When you include files, the absolute path for the DLL and header files changes. The files are placed in the .\exe_mcr\ folder when the archive is expanded. The file is not placed in the local folder. This folder is created from the deployable archive the first time the application is executed. The 'isdeployed' function is provided to help you accommodate this difference in deployed mode.
To work around this issue, copy the DLL to the current MATLAB folder before compiling and don't specify the full path.
  댓글 수: 2
KAE
KAE 2024년 3월 11일
Can I still use mcc in R2023 if I have Matlab compiler? I can't find more recent help on calling a .NET dll from an executable made from a Matlab function.
Walter Roberson
Walter Roberson 2024년 3월 11일
mcc is the command form of MATLAB Compiler, so Yes you can use it if you have MATLAB Compiler

댓글을 달려면 로그인하십시오.


KAE
KAE 2024년 3월 13일
You may need to unblock the dlls in Window properties, see here.

카테고리

Help CenterFile Exchange에서 Standalone Applications에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by