Call DLL files located in another directory

I have a console application ( NGameHost ) running in a specific directory ( C:\Program Files\NetworkGame3\api\ ). It uses the files available in this directory, and the console application works well when it launches on its own. It also provides various methods that use the DLLs (and other files, such as configuration files) from this directory. Now I have another console application (located elsewhere) that tried to call these methods and return the results. I set Copy Local: False so that it runs inside this directory instead of creating a local version. However, I get the error message "Could not load the file or assembly ... or one of its dependencies. The system cannot find the specified file."

How can I call methods from a console application located in a different directory?

+2
source share
3 answers

When you set copy local = false, what you are saying is that you donโ€™t copy the assembly to the local directory, in which case the assembly will be available in one of the places where it will be expected to run.

See How the runtime detects an assembly.

Your assembly must be either in the GAC or in one of the sensing zones.

+3
source

You can use the GAC, a configuration approach, or an assembly permission event.

This design bureau covers it in more detail:

http://support.microsoft.com/kb/837908

Also explore research paths:

http://msdn.microsoft.com/en-us/library/15hyw9x3(v=vs.71).aspx

+3
source

Recently, I hit my head against a brick wall, trying to solve a very similar problem. I have a DLL that I want to load at runtime, and it has its own dependencies. I couldnโ€™t understand all my life why it would load, but when I called the class constructor in the loaded assembly, the error was not raised, and the execution simply stalled, leaving you wondering what was going on.

It turns out that the dependency of the loaded assembly was in a different version of .NET, and there is App.Config in this code to enable mixed-mode assemblies. Therefore, of course, I also had to include this in my code, since I call the assembly, which calls the assembly in another version of .NET.

The error did not appear until I copied the entire dependent DLL into my application during development. Now I can delete them again! In doing so, I get a DLL Loader Lock warning. If I suppress it or ignore it, my code works.

In my case, then the resolution was:

 <?xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0"/> </startup> </configuration> 
0
source

Source: https://habr.com/ru/post/1386937/


All Articles