Question

I am using a .NET dll file for image operations and have added it in my C# application using "Add reference" in solution explorer and use its classes. There are many applications use that dll so I do not want to place the dll file in an application specific folder like:

  • C:\Program Files\<Application Name>\ or
  • C:\Program Files (x86)\<Application Name>\ or
  • C:\ProgramData\<Application Name>\ or
  • C:\Users\<Username>\AppData\

And would like to place the dll file in a common folder like C:\Windows\ or C:\Windows\System32 folder or any other folder that is commonly accessible by all applications in Windows.

It works fine when I put the the dll file in the same folder of the calling exe, but when I place it in C:\Windows\System32 directory, the C# code of my application is not able to locate the dll and gives error:

Unable to load DLL: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

How do I instruct my code to look for the dll in the system32 directory or in any other common directory?

What other common folder can I use for shared dll and libraries?

Was it helpful?

Solution

This is what the Global Assembly Cache is designed for. As listed in the MS documentation here.

Each computer where the common language run-time is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.

But there are pitfalls to using it so be aware of MS's own advice:

You should share assemblies by installing them into the global assembly cache only when you need to. As a general guideline, keep assembly dependencies private, and locate assemblies in the application directory unless sharing an assembly is explicitly required.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top