Dll's referenced in class library project are not being copied - c#

I have a solution which includes class library project and win forms app project. The thing is that when I try to run methods from class library that use third-party dlls (LeadTools to be specific), program crashes. When I check bin folder, I can see dll of class library project, but no third-party dlls, which should be there. How can I get this work?

In your class library project, add the third-party dll as a reference and make sure that on the reference properties the build action is set to copy to output directory.

Related

VS cannot debug referenced class library after I made an update to it

I've got two projects in my solution. Number one is a class library and the second one a console app.
The reference worked fine before, and I could debug the code in the class library when running the console app. But it stopped working after I've made a change (changes to methods) in the class lib. Now the debugger won't attach in the class lib. I can debug my console app.
I've tried to remove/add the reference (after a new build) but no luck.
It seems to reference an old dll. But I've checked the path to the reference and it points to bin/Debug in my class library project and the date matches when I re-built the class library.
Someone knows why this is happening?
Someone knows why this is happening?
Did you rebuild your class library project after you made a change (changes to methods) in the class lib? If not, that is the reason why you get this issue.
When you add the reference and make it points to bin/Debug in the class library project, the debugger will be easy to access the .pdb file in that path. However, if you made any change in the class lib without rebuild the project, the old .pdb file will not match the source code. So the debugger won't access in the class lib due to the mismatch .pdb file.
To resolve this issue, you should rebuild your class library project after made any modification in the class lib. Or you can just add the reference by Project-Reference rathan than Browse. In this case, Visual Studio will rebuild the referenced project automatically before debugging.

Use Open CV in class library

I'm creating application using my own dll files in C#.
I would like to create Class Library which uses Open CV. I have to add reference to project - Emgu.CV.dll and Emgu.Util. It's ok but OpenCV needs also extra dll files for example "opencv_calib3d231.dll" and others. They have to be in Debug folder when I want to run some Projet using OpenCV.
But what if I want to use OpenCv in my own class library? Where do I have to put this extra dll files?
Any idea how to fix this?
You cannot execute a class library by itself: ultimately a class library will always (indirectly) be used by some executable program. You have to ensure that dependencies of your class library can be found by said executable, for example by putting them in the directory that executable is in.
So, if you have an executable project (Project A) and a class library (Project B) used by the executable project that has native dependencies like opencv_calib3d231.dll, it suffices to ensure the native dependencies are in Project A's directory at runtime.
If you are developing a class library that will be used by other developers in their programs, you should distribute the dependencies of your class library with the library (or at least provide instructions on how to obtain the dependencies in your documentation). They can then ensure the operating system can find the dependencies upon loading your class library.

Visual Studio 2010: How refer to a C# .Net class library project with third part dependencies

This is probably a very basic question but I haven't found any detailed information about how project references works in Visual Studio.
I have a Visual Studio 2010 C# solution containing a MainApp project and a C# class library project with third party assemblies inside. When referring to the class library project from the MainApp project, should I just add a project reference or do I need to add references to the third party assemblies within the class library project as well?
In some cases it seems like the third party assemblies are not loaded correctly if I just have the Class Library project reference in my MainApp project although all DLL files (incl third party DLLs) show up in the output folder when building the complete solution.
Edit: I've posted a more specific question since the general answer did not help in my case: How to refer self-contained C# class library project with IronPython inside (Visual Studio 2010)
When using thrid party assemblies/dlls I find it bect to create a folder in a project called "Dependencies" and place them in there, that way they don't get lost or hidden in amongst your source.
Your class library project should reference the thrid party assemblies. You'll need to browse for those (after clicking add reference) and then set the Copy Local property True, that way they will be copied to the directory into which any compiled code is placed.
Your other project just needs to reference your class library project(remember to set the Copy Local property), select it from the Projects list after clicking add reference.
Oh I forgot to add your code files that refer to any publics on the referenced assemblies will require a using statement to link to them.

DLLNotFoundException The Specified module could not be found

I make use of the Belgium Identity Card SDK for reading data from a idcard.
The SDK exists of 2 components: interface dll and a wrapper dll.
In VS2010, i can make a reference to the interface dll, but not to the wrapper dll, so I put it manually in the bin folder. When I migrate my application to another pc on the localhost, it is not able to find the wrapper dll.
Not even when I (on the 2nd pc):
-installed the sdk.
-put the wrapper dll into the bin folder and system32 folder
In visual studio, properties of the interface dll, I've set "Copy Local" to true.
What can I do?
This could just be a difference in path names between machines.
I would create a folder at the top level of your solution and place these DLLs in there. Call it something obvious like "Solution dependencies". Then you can reference them as needed and set them copy to local as required. You wont always be able to reference a DLL, especially if it isn't .NET compatible.
I'm curious about your statement of interface and wrapper dlls. Is the wrapper dll not meant to be a .NET wrapper for a C++ style dll?

Referencing an external .NET DLL provided by another application in C#

I have a C# project which references a DLL (call it external DLL) which comes with another application. When I build my project, due to the reference, the external DLL gets automatically added to my project output. And when I run my project it loads the external DLL from my project folder.
The other application, which the external DLL belongs to, is developed by another team and the DLL is regularly updated. I don't want to package their DLL with my project. Instead I would like to have my project load their DLL when executed -- rather than pick the DLL copy from my project's folder.
Now I know that this is possible through reflection. I know that I can do an "Assembly.Load" and pick the DLL. But because I use the types from the external DLL all through my code, I would like the code to be statically type checked.
Here's what I would like:
Be able to compile my project by referencing the external DLL and thus get static type checking.
When the project is run, the external DLL is picked up from the other application's folder and not the copy of the DLL which is in my project's output folder.
Is there any way to solve this problem? Is there some middle ground between adding a reference and using reflection?
The most immediete solution to your problem is to change the properties of the reference. There is a setting called Copy Local. Set that to false and it'll stop copying the DLL to your project's output. You can access the properties of the reference by expanding the references folder in your solution, right-clicking on the reference in question, and clicking properties to open the properties pane.
The fact that Visual Studio copies the DLL to your project's output folder at build time doesn't really matter to the .Net Framework at runtime. All that matters is that the assemblies you reference are available to the framework either in the paths it searches or in the global assembly cache.

Categories