GregD
GregD

Reputation: 195

DLL Not found: referencing dependent DLLs

I'm attempting to implement a C++ DLL (of my own creation) that uses the Intel Performance Primitives in a C# forms application. I'm getting a "DLL Not Found Exception" when I attempt to run the program. One possible reason put forward in other posts on this site is that there are dependent DLLs that must be referenced and in fact after downloading DpendencyWalker I found that my DLL uses "IPPS-7.0.DLL".

My problem is that it is unclear to me how to reference these dependent DLLs. I've added the IPPS-7.0.DLL containing folder to referenced paths as well as added references to the "IntelCppOptPkg" and "IntelLibOptPgk" assemblies but this has not solved the problem.

So, am I correct in believing this is the problem? And if so, how does one reference a depedent DLL in managed code?

Thank you.

Upvotes: 1

Views: 6468

Answers (2)

Dmitry
Dmitry

Reputation: 17350

Managed code can not reference unmanaged dll the same way it references managed assemblies. Managed references actually change the meta data of your assembly:

The compiler records static references in the assembly manifest's metadata at build time. ... The preferred way to reference an assembly is to use a full reference, including the assembly name, version, culture, and public key token (if one exists).

Native dlls simply don't have this .NET meta data associated with them. They have to be copied manually in the Post Build step or during deployment. There is a workaround but I don't think it will work if your managed app is platform independent (Any CPU) and you have x86 and x64 versions of unmanaged dlls.

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 941218

You don't reference them, they are not .NET assemblies. You just need to make sure that the DLL(s) get copied to your build directory. Easiest way to do that is with Project + Add Existing Item, select the DLL from wherever it was copied. Then select the added file and in the Properties window set Build Action = Content, Copy to Output Directory = Copy if newer. Checking-in the DLL(s) in source control is generally a good idea btw.

Upvotes: 2

Related Questions