Unable to load DLL 'libMatlab​CppSharedL​ib24_1'

4 次查看(过去 30 天)
Hi all,
I am trying to deploy a MATLAB class that inherits from MATLAB Handle Class to a .NET Framework 4.8 project. Most of the steps I have replicated from this guide using the MATLAB 2024a complier and the MATLAB 2024a Runtime.
So far I get a successful compliation on Visual Studio 2022 but upon running I get the following Exception:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Unhandled Exception: System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.Runtime.MATLABRuntime' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libMatlabCppSharedLib24_1': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at MathWorks.MATLAB.Runtime.RuntimeInterop.runtime_create_session(IntPtr[] options, UInt64 size)
at MathWorks.MATLAB.Runtime.RuntimeInterop.InitializeApplication(String[] options) in /mathworks/devel/bat/filer/batfs2557-0/BR2024ad.2537033.BR2024ad.2532478.pass/build/matlab/standalone/dotnet_runtime/src/dotnet_runtime/RuntimeInterop.cs:line 91
at MathWorks.MATLAB.Runtime.MATLABRuntime..cctor() in /mathworks/devel/bat/filer/batfs2557-0/BR2024ad.2537033.BR2024ad.2532478.pass/build/matlab/standalone/dotnet_runtime/src/dotnet_runtime/MATLABRuntime.cs:line 35
--- End of inner exception stack trace ---
at MathWorks.MATLAB.Runtime.MATLABRuntime.StartMATLAB(String ctfFile)
at Test.Program.Main(String[] args) in <redacted>\Program.cs:line 19
Press any key to continue . . .
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
It appears to be suggesting that it is unable to locate the 'libMatlabCppSharedLib24_1'. I have checked in <MATLABROOT>/MATLAB Runtime/R2024a/runtime/win64/ and can actually find the libMatlabCppSharedLib24_1.dll in question.
I have referenced the MathWorks.MATLAB.Runtime.dll and MathWorks.MATLAB.Types.dll from the <MATLABROOT>/MATLAB Runtime/R2024a/extern/dotnet/netstandard2.0/ directory. Is there something else I need to make sure I need to configure or double check?
Would appreciate any pointers or improvements to this post.

采纳的回答

Ying Lia Li
Ying Lia Li 2024-4-15
I have found my solution and hopefully it helps anyone else who comes across this problem.
The problem was in the PATH environment variable. I have both 2023b and 2024a installed, and although 2024a variables were higher in the list, the .NET application kept running the 2023b matlab runtime instead. I removed the 2023b runtime path variable and was able to get past the error above.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deploy to .NET Applications Using MWArray API 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by