Why Matlab executable cannot load .NET library? The DLL path is correct.
조회 수: 14 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (2개)
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
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
2024년 3월 11일
참고 항목
카테고리
Help Center 및 File Exchange에서 Standalone Applications에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!