I cant import a dll into my project references C# .net Project - asp.net

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.

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).

Related

ASP.Net Website project fails to build after updating a referenced DLL

So I have an ASP.NET VB website that references several other projects (their DLLS are just put in the site's bin folder). I need to update a small piece of code in one of the projects, which I have done and it builds fine. However, when I copy over the new DLL to the website's bin folder it fails to build, and all the Imports statements say "BC40056: Namespace or type specified in the Imports xxx doesn't contain any public member or cannot be found", which results in a ton of errors like "is not defined" . There is no reference to the updated DLL in the website project's properties, but if I put the old version back it's all fine.
The project was copied from a server and the vbproj file contained references to other DLLs, but the HintPaths were a mixture of mapped drives and ..\..\..\. I've updated these so that they're all the full server location path, but this has made no difference. I tried adding the project to the same solution as the website and added a reference to the project instead, but this also made no difference.
I've done plenty of Googling but have yet to find a solution. Any help would be very welcome!
A few things
You don't want to just "place" the .dll's in the bin folder. One big reason is that when you do a "clean" project, the bin folder is deleted. So, anytime you do a clean project, what is in the bin folder is cleaned out. And a developer will often do a clean project if some kind of problem is occuring.
I would place those files in some folder in the project. (create a folder, or if its only one or two .dll's, then place them in the root of the project). At compile time, the .dll's will be copied to the bin folder. And if you using web deployment, then you can choose to have the .dll's all combined into one .dll. So, once again, you can see it makes little sense to place the .dll's in the bin folder, since during a build, they will not be required, and as noted, the resulting bin folder can and will as a "regular" development process be re-created (emptied out). I seen a good number of projects in which the developer did place the .dll in the bin folder (because they did not know where else to place the .dll's, and that was seemly the only place that the application worked. But, during a web build + deployment to the production server, those .dll's can be left behind - they not be copied to the final "deployment" build. (I'm basic saying don't do this!!).
You can also consider just creating folder called "packages" in the root. This is where all the nuget packages are placed. So, some folder for those .dll's is the idea here.
The other big issue? Well, just dropping some .dll's in some place does NOT give you the developer all the methods and properties of those .dll's when writing code (we are assuming these are managed code - not win x32 .dll's).
So, without adding a reference to that assembly, then I can't see how the project will even compile correctly, and how syntax checking, and general use of the assembly will ever work during the development process (so VERY perplexed that you don't have references to those .dll's - that as a general rule can't work).
Now, to use the assemblies? Yes, you want to add the .dll as a reference to the project.
So, in references, add the .dll as a reference.
And then in the property sheet for the refence? Make sure you have the "copy local" set = true.
eg this:
So, above is GhostScript.net reference. (a open source library to manipulate pdf's).
Note the long path name for the .dll location. But, MOST important is the copy local setting = true. This means during a compile and build (which as noted can clean out the bin folder), then the .dll will be output to the final build in the bin folder.
So, I can't see how you can compile anything without an actual reference to the .dll. That is quite much assumed and a given - else I see no way how your project can compile under any circumstances.
So, referance the .dll, and that should allow use of the class(s) and objects, and enable your code to compile. And make sure the copy local = true, as that is the process that will copy + place the .dll in the final output (bin) folder when you compile.
So it turns out that the project for the DLL I was trying to reference had the Target CPU set to x64. Changing this this to 'AnyCPU' then allowed me to reference it.
This post gave me the answer: Could not load file or assembly ... An attempt was made to load a program with an incorrect format (System.BadImageFormatException)

How to add an external library to QT?

I am trying to create a project assosiated with the SimConnect SDK.
I am new to QT, and in Visual Studio, I just had a SimConnect.h file, a .lib file, and a .dll file, and I managed to make it work. Now I am trying to create a C++ widget project, using the same SDK, but in QT.
I put the header file in my QT project's folder, where the other default code and header files are located, and then I went to the project and added them as existing files, as I read in Google. I'm having problems with the actual library.
I've been searching Google for a guide on how to add a library file to the project, I did some things I saw on the internet, like the LIBS line for example, but I probably did it wrong, even though it looked very simple.
I am not sure where to drop my dll/library files in the project directory, maybe the problem is I always put them in the wrong spot.
The furthest I got to, was an error message saying "Unresolved external symbol", and a red writing saying ".obj file not found" on every function I tried to use from the SimConnect functions, which probably means QT couldn't find my library/dll file.
I also tried to add the libraries from the "Add library" option in the project, but that didn't work too.
EDIT: it also warns "warning: LNK4272: library machine type 'X86' conflicts with target machine type 'x64'" maybe it has to do something with it.
(Posted on behalf of the OP).
Solved! My problem was my machine was set to 64bit, while the library was set to 32bit, so I downloaded the 32bit kit, and ran the project through that, and it worked!

Tracing where a dll in the bin folder comes from

I noticed today that whenever I build a word add in project of mine, Microsoft.Sharepoint.dll is being copied into the bin folder and is subsequently included when publishing.
Is there an easy way to see why this (annoyingly large) dll is being included when publishing?
It isn't referenced directly. There are 3 dependencies in the project page and I've checked all these projects and none of them reference it directly either. Do I need to continue following the dependencies of those projects too?
Is there not some kind of log file for a build that could give me a hint?
EDIT:
The problem was that my project referenced a project that referenced a project that had a reference to Microsoft.SharePoint.dll with copy local set to true. I had to delete the dlls from all projects and rebuild with copy local set to false. I didnt realise that the 3rd party dll would be copied into my project.
If this is being pulled in due to a dependency from another DLL, then try looking at all of your DLLs in Dependency Walker. It finds all of the dependecies that a dll has. This is usually only when they are actually being used/bound, but you can also use the Fusion Log Viewer to see where all DLL binds are being bound from.
You could have a a look at reflection mechanism of asp.net or if not you could run trace using firebug for cross reference on browser ,

VS 2005, website project: managed C++ assemblies require dependencies in path, not bin dir?

I'm trying to build a VS 2005 website project which depends on several managed C++ assemblies. One of the managed C++ assemblies depends (static-load) on an unmanaged DLL which uses __declspec(dllexport) to export classes.
For some reason, I get the following build error:
Error 4 The specified module could not be found. (Exception from HRESULT: 0x8007007E)
(From build output details):
(0): Build (web): The specified module could not be found. (Exception from HRESULT: 0x8007007E)
when I build with the unmanaged DLL in the website's \Bin\ directory, but not in the path. If I put the unmanaged DLL in the path, then re-start visual studio, it builds and runs just fine.
Note: This thread seemed related, but I haven't gotten as far as deployment yet: Unmanaged DLLs fail to load on ASP.NET server
Is there any way to get this .sln building correctly with unmanaged DLL's in \Bin\ rather than the path? (I'd really prefer to keep these as part of the website, not the system)
Edit:
It seems I've misunderstood the purpose of the \Bin\ folder to some degree. Sounds like nothing except managed assemblies should go there. (So COM objects and other unmanaged DLLs they rely on which I've been placing there probably belong someplace else.)
I believe that ASP.NET copies your assemblies around quite a bit, to avoid locking the original DLL (which would prevent overwriting with a newer version). Then when you do overwrite it, it needs a copy of the old version until all outstanding requests complete, alongside the new version being used for new requests.
In summary, your DLL doesn't run from the \bin\ directory where you put it, and it looks for native dependencies where it actually does run.
Your options are to put the native DLLs in the path, or else add code to explicitly copy them to the "real" assembly directory as needed. But your code shouldn't even have permission to write to the filesystem, so I think you're stuck using the path.
Do note, though, that you can add directories to the application's own environment, without affecting the global path. For example, p/invoke SetDllDirectory Don't add \bin\ though. Put your native DLLs in a separate directory like \bin\native or \bin\x86, so when you change the search path you don't change which managed DLLs are found.
Edit:
This only works if the managed DLL delay loads any unmanaged native DLLs it links against (using /DELAYLOAD). Otherwise compilation of global.asax (or wherever the path setting happens) will fail.

Cannot find correct file called qtnetwork4.dll

Guys I've written app in qt and when trying to run it (double click on *.exe) I'm getting error that this application cannot start because qtnetwork4.dll isn't available. I've searched my drive and I found few files with this name (and copied one by one every time trying to run my app) but none of them seems to work. How can I solve it?
place into your *.exe - folder appropriate dll-s from %QT_PATH%\bin\
There is an app called Dependency Walker that will let you know what functions in qtnetwork4.dll are being used in your program. It can be found at the following:
http://www.dependencywalker.com/
All of the DLLs your program use will be from the same installation as the qmake.exe that is used to compile the program. If you are using Qt Creator you can see where the qmake.exe your using is located by going to:
tools->options->Qt4
Get the DLLs that are located at the path displayed here to make sure they will work with your program.
On windows, DLL are looked for in folder where executable lies, then using "PATH" environenment variable.
In your case, you want to put your dll along your executable, taking them from the sdk you're using to compile
The following page provides a lot of additional information on the subject (example, plugins, strategy for building installers)
To force using QtNetwork and linking it, you have to put
QT += network
in your poject file.
If you're sure you're not using it, you can use
QT -= network

Resources