0

When I try to import a .dll (cplex1280) into my asp.net project references, I get an error saying Please make sure that the file is accessible, and that it is a valid assembly of COM componet.

The weird thing is that I can build my application even though this dll isn't referenced. For people who are familiar with CPLEX, I successfully included the ILOG.CPLEX.dll and ILOG.Concert.dll

Currently the directory for my project is setup as ProjFolder/Myproj. There is a folder ProjFolder/bin and a folder ProjFolder/myproj/bin where I included the cplex1280.dll file. There is also a copy of the cplex1280.dll in one of my Program Files folder. I tried to add a reference of this dll from each of these locations, but I keep getting the same error. When I looked up this issue, I saw two solutions that people recommended. Here is the post that I used for help.

One solution was trying to use

regsvr32 "foo.dll"

on the file. When I try this, I get an error saying

The module "cplex1280.dll" was loaded but the entry-point DllRegisterServer was not found. make sure that "cplex1280" is a valid DLL or OCX file and then try again.

The other thing I tried using was dll import

[DllImport("cplex1280.dll"]

I was a little confused by the Microsoft documentation. It doesn't specify what folder to put the dll in and usually there is a function definition after the import statement, but my program uses multiple functions from this dll. If someone could explain this import method in more depth I would appreciate it.

Chase
  • 33
  • 2
  • 11
  • A quick google search suggests that this dll is a native module, i.e. neither a .NET assembly nor a COM in-proc server. What makes you think you need to add it as a reference? – 500 - Internal Server Error Aug 16 '19 at 17:38
  • I'm somewhat new to .net development and I've just been including all of my dll's as references. Recerences -> Add Reference. – Chase Aug 16 '19 at 17:40
  • Do you suggest that I do something differently? – Chase Aug 16 '19 at 17:41
  • Yes, don't add this - it will be loaded as needed by the other modules that you successfully added references to. – 500 - Internal Server Error Aug 16 '19 at 17:42
  • Thats kinda what I thought, but this error is saying that the module cant be found – Chase Aug 16 '19 at 18:09
  • System.DllNotFoundException: Unable to load DLL 'cplex1280': The specified module could not be found. (Exception from HRESULT: 0x8007007E) – Chase Aug 16 '19 at 18:09
  • Should I move it to a specific place in my project directory? – Chase Aug 16 '19 at 18:09
  • If its location is not on your search path, it probably needs to be in your bin folder (where your own dlls are emitted). – 500 - Internal Server Error Aug 16 '19 at 18:13
  • Your project added its managed wrapper as reference, so you don't need to consume the native library directly. However, when you run this project, the program must be able to locate that native library. Usually you can drop the native library to folders like `%windir%\system32`, https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order – Lex Li Aug 16 '19 at 18:18
  • I tried putting the all of the cplex dll's in my windows/system32 folder, but I'm getting the same error. I don't know if this is relevant, but my project is located in a network drive and my windows folder is on my C drive – Chase Aug 16 '19 at 18:25
  • At this point, having tried loads of things at random, who knows what state you machine is in. Modifying system 32 is a terrible mistake. Don't do that. Reverse that change. – David Heffernan Aug 17 '19 at 05:56

1 Answers1

1

As mentioned in the comments, cplex1280.dll is a Native DLL. It is a shared library for the CPLEX C Callable Library. For your .NET application, you should only add references to ILOG.CPLEX.dll and ILOG.Concert.dll (see the readmeWindows.html file in the directory where you installed CPLEX).

Dropping the CPLEX dll's into your windows/system32 directory is not recommended (see DLL Hell). Instead, when you deploy your application, you either need to make sure that the directory where cplex1280.dll is located is included in the PATH environment variable or that it lives in the same directory as your ASP.NET executables. This gives you more flexibility when you have to support different products that use different versions of CPLEX (or even multiple releases of the same product).

rkersh
  • 4,447
  • 2
  • 22
  • 31