NLoptNet
NLoptNet copied to clipboard
DllNotFoundException nlopt_x64.dll
I NuGet installed NLOptNet and copy/pasted some code from the ReadMe
When I execute the line: var solver = new NLoptSolver(NLoptAlgorithm.LN_COBYLA, 1, 0.001, 100)
I get the below error
(Note: I am using .NET Framework 4.8. I also downloaded and installed https://github.com/stevengj/NLoptBuilder/releases/download/v2.6.1/NLopt.v2.6.1.x86_64-w64-mingw32.tar.gz and I even copied the libnlopt.dll from its bin directory to my executable directory and renamed it to nlopt_x64.dll.)
System.DllNotFoundException HResult=0x80131524 Message=Unable to load DLL 'nlopt_x64.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) Source=NLoptNet StackTrace: at NLoptNet.NLoptSolver.nlopt_create64(NLoptAlgorithm algorithm, UInt32 n) at NLoptNet.NLoptSolver..ctor(NLoptAlgorithm algorithm, UInt32 numVariables, Double relativeStoppingTolerance, Int32 maximumIterations, Nullable`1 childAlgorithm)
What OS are you running on? And you verified that you're running an x64 build of your C# application? Perhaps there's a dependency missing. You could try dumpbin /DEPENDENTS nlopt_x64.dll
and verify that you have all the dependent DLLs. I'm assuming that the .NET 4.7 target will automatically work for .NET 4.8, but I don't know that for sure. Are you able to use .NET Core instead?
Ok, I realized my mistake. Since it was looking for nlopt_x64.dll, not nloptNET_x64.dll I thought it was looking for the underlying nlopt library. So I installed it from the nlopt binaries for windows. I now realize that NuGet installed the nloptnet library as nlopt.dll. I renamed it to nlopt_x64.dll and now it works.
May I suggest updating the NuGet package to install the library with the correct name? Alternatively, add instructions in the README file.
In any case, thank you ever so much for making the .NET interface available.
Fixed in 1.4.2