I have a .NET console app that references a DLL. It runs fine if the DLL is in the same folder as the EXE but I would like to put the DLL in a different folder. How can I do that?
Using DLL File Step 1 - Open Visual Studio then select "File" -> "New" -> "Project..." then select "Visual C#" -> "Windows Forms application". Step 2 - Design the form as in the following image: Step 3 - Add a reference for the dll file, "calculation. dll", that we created earlier.
One of the things I did miss was a clear direction on how to reference a . NET dll directly (and of course still enjoy the benefits of intellisense), basically the same thing as doing Project > Add Reference > Browse in Visual Studio. And that's it!
If the DLL is in a sub folder you can add this folder to the AppDomain private path.
The private bin path of an AppDomain
cannot be changed once the AppDomain
has been created (AppDomain.AppendPrivatePath
is obsolete), if you don't want to create a new AppDomain
, you can modify the probing element in the App.config.
If it's not in a sub folder, things get more complicated, you can load the assembly using its full path, but if it references other assembly, the CLR won't be able to resolve the dependencies.
If you want to resolve dependencies, you can add an handler to AppDomain.AssemblyResolve and fetch the needed assembly in your specific folder.
Another possibility is to place this DLL (and dependencies) in the GAC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With