Unable to load DLL 'libMatlab​CppSharedL​ib24_1'

9 Ansichten (letzte 30 Tage)
Ying Lia Li
Ying Lia Li am 12 Apr. 2024
Beantwortet: Ying Lia Li am 15 Apr. 2024
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.

Akzeptierte Antwort

Ying Lia Li
Ying Lia Li am 15 Apr. 2024
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.

Weitere Antworten (0)

Kategorien

Mehr zu Deploy to .NET Applications Using MWArray API finden Sie in Help Center und File Exchange

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by