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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If the DLL is in a sub folder you can add this folder to the AppDomain private path.
The private bin path of an
AppDomaincannot be changed once theAppDomainhas been created (AppDomain.AppendPrivatePathis obsolete), if you don’t want to create a newAppDomain, 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.