I want to load & unload assemblies that are found outside the current app domain. Upon reading the following threads,
- AppDomain.Load() fails with FileNotFoundException
- Unloading the Assembly loaded with Assembly.LoadFrom() <- I couldn't understand the answer from this thread
- Loading/Unloading assembly in different AppDomain <- I placed the target assembly folder location in the private bin path which resulted in
FileNotFoundException
I have the following code that raises the FileNotFoundException
.
// let's assume that the executable running this code is found at "F:\\Test.exe"
// this is the assembly I want to load
string pathToAssembly = "C:\\Documents\\hello.dll";
// copied directly from the 1st link
AppDomain dom = AppDomain.CreateDomain("some");
AssemblyName assemblyName = new AssemblyName();
assemblyName.CodeBase = pathToAssembly;
Assembly assembly = dom.Load(assemblyName); // raises FileNotFoundException
I checked the documentation: https://learn.microsoft.com/en-us/dotnet/framework/app-domains/how-to-load-assemblies-into-an-application-domain https://learn.microsoft.com/en-us/dotnet/framework/app-domains/how-to-unload-an-application-domain
But it didn't use AppDomain to load AND unload from an absolute path.
Based from the 2nd link, AppDomains search for the assemblies within its current executable's directory path. Which, of course, I need to work around that because I need to load a managed library outside of the current directory.
And, for additional information, I'm on WPF using .NET framework 4.7.2
TLDR: What do I need to change the "look" directory of the AppDomain? or what can I do to fix this?