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.
Related
I have to create a COM library from a C# project, but I'm pretty stuck with referencing the external libraries.
I have set "Make assembly COM-Visible" in the project's properties and when I build it creates the dll and it puts all required dll's in the bin/Release directory.
Libraries used
All libraries are .NET imported with NuGet or System libraries.
Creating the .tlb file
When I run a command to create a .tlb file, it is created, but it also shows a warning:
tlbexp.exe "MyLib.dll"
TlbExp : warning TX00131175 : When cross-compiling, all type library references should be included on the command line to ensure the correct bit-specific type libraries are loaded.
Assembly exported to 'C:\Workspace\MyProject\bin\MyLib.tlb'
It looks like this library is ready to be shipped, but I'm wondering if I can just ignore the warning.
And, what is the best way to ship this COM-Visible library?
Can I just ship the entire bin/Release directory, or should I use another method?
Well the .tlb is needed just to reference your library from a development tool ( for example Visual C++ ), referencing correctly does not mean that program, after compiling correctly, will work. This because you need to proper install the dll on the target machine, typically you need to xcopy the dll with all dependencies, and then use regasm.exe ( specifying the /CODEBASE flag I suggest, so you can point surely the dll you want on your file system ). Of course even proper Framework has to be installed too.
I have an app that references a .dll that was built with Costura/Fody i.e The dll has all its references embedded. When I run the console app, the references from the dll are not unpacked so the console app throws an exception saying missing .dll etc. as it needs those resources to run.
i.e. AssemblyA.dll embeds MyAssembly.dll when built with Costura/Fody. ConsoleAppC references and embeds AssemblyA.dll but also needs MyAssembly.dll to run. I do have a reference to MyAssembly.dll in ConsoleAppC so that it will compile (but CopyLocal is set to false). I was thinking that MyAssembly.dll would be made available to ConsoleAppC when AssemblyA.dll's embedded resources are unpacked?
This is not working but is my scenario valid in any way or can you only utilise embedded resources from ConsoleAppC and not the ones that were embedded in AssemblyA.dll?
Thanks in advance for any help
Mike
What you're trying to do isn't possible with Costura.Fody. What Costura does is embed libraries directly into the main assembly. This means that if you embed the built assembly into another project, it can't see the sub assemblies.
For example, consider the following project structure:
AssemblyA
Foo.cs
References:
SubAssembly1.dll
SubAssembly2.dll
SubAssembly3.dll
AssemblyB
Assume that Costura.Fody is used to embed the sub assemblies in AssemblyA, creating a single DLL file, AssemblyA.dll
If you embed AssemblyA.dll in AssemblyB, then you will not be able to access classes in SubAssembly1.dll. You will only be able to see any of the classes that are directly in AssemblyA.dll, such as those contained in Foo.cs - you will not be able to see any of the libraries referenced by/embedded in AssemblyA.dll.
See this answer to a similar question, where the answerer suggests using ILMerge instead.
I have a class, written in C#, shared between a C# and a C++ application.
To use it in the C++ app, I wrote a CLI wrapper class.
Simple diagram:
C++ App ---accesses---> CLI Library ---accesses---> C# library
Unfortunately, because of some name conflicts beyond my control, the C# and C+ applications need to be in separate directories.
What options are there for having my C++ app access these libraries in another directory?
Can I use AfxLoadLibrary in my C++ app to load the CLI library? In that case,
would the CLI dll and the C# dll have to be in the same directory?
Can I have the managed CLI library load the C# library dynamically?
Are there any other options that I'm missing?
Another option:
Add a yourapp.exe.config file to your exe folder, listing one or more subfolders as probing paths. Put the files for each library assembly into one of the subfolders. You can put all assemblies (except the application assembly) into one folder if you want.
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.
I making a small cross platform project, and wan't my webservice calls, in a separate class library project. I've created a Xamarin.iOS solution, and added a class library, which is referenced from the application. In the class library, I've defined a simple webservice class that calls a webservice and deserializes the json into a POCO using Newtonsoft.Json. The problem is that because Newtonsoft.Json is referenced from the class library and not the application, the Newtonsoft.Json.dll file is not linked into the application - only the class library dll - and I get a file-not-found when deserializing.
I tried to use --linkskip=Newtonsoft.Json in the application but that doesn't help.
How do I force the buildhost to link that dll into the application?
I finally found a solution. Since the linker don't care to embed the newtonsoft.json.dll in the solution, I add the file to the class library, besides referencing the one in the Component folder. That seems to work. No more "missing file"